From 707c1ec2eacd3639f254c1d5b24373b2e1574013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E8=89=AF=E6=B6=9B?= <3159961255@qq.com> Date: Sun, 4 Dec 2022 22:20:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?for=E5=BE=AA=E7=8E=AF=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...52\347\216\257\344\275\234\344\270\232.md" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "20 \347\237\263\350\211\257\346\266\233/20221203 for\345\276\252\347\216\257\344\275\234\344\270\232.md" diff --git "a/20 \347\237\263\350\211\257\346\266\233/20221203 for\345\276\252\347\216\257\344\275\234\344\270\232.md" "b/20 \347\237\263\350\211\257\346\266\233/20221203 for\345\276\252\347\216\257\344\275\234\344\270\232.md" new file mode 100644 index 0000000..ba974d1 --- /dev/null +++ "b/20 \347\237\263\350\211\257\346\266\233/20221203 for\345\276\252\347\216\257\344\275\234\344\270\232.md" @@ -0,0 +1,40 @@ +# for 循环作业 + +1.让用户输入一个数字,根据这个数字,循环输出"我爱学习,我爱java",比如,用户输入数字 9 就在控制台输出9行"我爱学习,我爱java" + +```java +import java.util.Scanner; + +public class A4 { + public static void main(String[] args) { + Scanner sc =new Scanner(System.in); + System.out.println("请输入你要重复多少次这个话"); + int num =sc.nextInt(); + for (int num1=0; num1 Date: Tue, 6 Dec 2022 20:54:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?while=20=E5=BE=AA=E7=8E=AF=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20221205 while\344\275\234\344\270\232.md" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "20 \347\237\263\350\211\257\346\266\233/20221205 while\344\275\234\344\270\232.md" diff --git "a/20 \347\237\263\350\211\257\346\266\233/20221205 while\344\275\234\344\270\232.md" "b/20 \347\237\263\350\211\257\346\266\233/20221205 while\344\275\234\344\270\232.md" new file mode 100644 index 0000000..e252763 --- /dev/null +++ "b/20 \347\237\263\350\211\257\346\266\233/20221205 while\344\275\234\344\270\232.md" @@ -0,0 +1,61 @@ +# while 作业 + +## 猜数字游戏 + +```java +import java.util.Random; +import java.util.Scanner; + +public class A6 { + public static void main(String[] args) { + Random r = new Random(); + Scanner sc =new Scanner(System.in); + int desNumber = r.nextInt(100)+1; + System.out.println("我心中的数生成"); + + while (true){ + System.out.println("猜猜我心中数是多少,只有三次机会哦,数值在0~100之间"); + for (int i = 0; i < 3; i++) { + int number = sc.nextInt(); + + + if (number > desNumber) { + System.out.println("你猜的数字过大"); + } else if (number < desNumber) { + System.out.println("你猜的数字过小"); + } else { + System.out.println("恭喜你猜对了"); + System.out.println("游戏结束"); + break; + } + if (i == 2) { + System.out.println("抱歉你的次数用完了"); + System.exit(0); + } + if (i < 3) { + System.out.println("你还有" + (2 - i) + "次机会!!!"); + } + } + } + } +} + +``` + + + +## 九九乘法表 + +```java +public class A7 { + public static void main(String[] args) { + for (int i=1;i<=9;i++){ + for(int j=1;j<=i;j++){ + System.out.print(i+"*"+j+"="+i*j+"\t"); + } + System.out.println(); + } + } +} + +``` -- Gitee