diff --git "a/21 \345\210\230\345\260\221\346\265\267/12 7 Java\347\254\224\350\256\260.md" "b/21 \345\210\230\345\260\221\346\265\267/12 7 Java\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..a5da98416c27a78c8efd94952d35e1f17afd86f8 --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/12 7 Java\347\254\224\350\256\260.md" @@ -0,0 +1,49 @@ +**3. while****循环** + +**3.1** **循环语句****-while****循环** + +while循环完整格式: + +``` +初始化语句; +while (条件判断语句) { +循环体语句; +条件控制语句; +} +``` + +while循环执行流程: + +①执行初始化语句 + +②执行条件判断语句,看其结果是true还是false + + 如果是false,循环结束 + + 如果是true,继续执行 + +③执行循环体语句 + +④执行条件控制语句 + +⑤回到②继续 + +``` +public class WhileDemo { +public static void main(String[] args) { +//需求:在控制台输出5次"HelloWorld" +//for循环实现 +for(int i=1; i<=5; i++) { +System.out.println("HelloWorld"); +} +System.out.println("--------"); +//while循环实现 +int j = 1; +while(j<=5) { +System.out.println("HelloWorld"); +j++; + } + } +} +``` + diff --git "a/21 \345\210\230\345\260\221\346\265\267/java 12 5.md" "b/21 \345\210\230\345\260\221\346\265\267/java 12 5.md" new file mode 100644 index 0000000000000000000000000000000000000000..aecba7ddc81347b6fbc1be6a10019988d0cc4c77 --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/java 12 5.md" @@ -0,0 +1,130 @@ +``` +import java.util.Scanner; + +public class czc { +/* private static final char 夏利 =1; + private static final char 富康 = 2; + private static final char 桑塔纳 = 3;*/ + + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入车型"); + int num= sc.nextInt(); + System.out.println("请输入路程"); + double Num = sc.nextDouble(); + switch (num){ + case 1: + if (Num<=3){ + System.out.println(+Num*3); + } + if (Num>3){ + System.out.println((Num-3)*2.1+9); + } + break; + case 2: + if (Num<=3){ + System.out.println(Num*4); + } + if (Num>3){ + System.out.println((Num-3)*2.4+12); + } + break; + case 3: + if (Num<=3){ + System.out.println(Num*5); + } + if (Num>3){ + System.out.println((Num-3)*2.7+15); + } + break; + default: + System.out.println("输入错误"); + break; + + } + } + } +``` + +``` +import java.util.Scanner; + +public class tian { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + System.out.println("请输入年份"); + int year = sc.nextInt(); + System.out.println("请输入月份"); + int Num = sc.nextInt(); + System.out.println("请输入日份"); + int num = sc.nextInt(); + switch (year){ + case 2000: + if(year%4==0&&year%400!=0||year%400==0){ + System.out.println(year+"是闰年"); + } + if(Num >= 3){ + System.out.println((Num-1)*30+num+1); + } + System.out.println((Num-1)*30+num); + } + } +} +``` + + + +``` +import java.util.Scanner; +//a o e i u v +public class zimu { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入一个字符"); + char num = sc.next().charAt(0); + switch (num){ + case 'a': + case 'A': + case 'e': + case 'E': + case 'i': + case 'I': + case 'o': + case 'O': + case 'u': + case 'U': + case 'v': + case 'V': + System.out.println("这是韵母"); + break; + default: + System.out.println("这是声母"); + + + } + if(num>='A'&& num<='Z'){ + System.out.println("大写字母"); + } else { + System.out.println("小写字母"); + } + } +} +``` + +## 3. 流程控制语句 + +在一个程序执行的过程中,各条语句的执行顺序对程序的结果是有直接影响的。所以,我们必须清楚每条语句的执行流程。而且,很多时候要通过控制语句的执行顺序来实现我们想要的功能。 + +### 3.1 流程控制语句分类(了解) + +​ 顺序结构 + +​ 分支结构(if, switch) + +​ 循环结构(for, while, do…while) + +### 3.2 顺序结构(了解) + +顺序结构是程序中最简单最基本的流程控制,没有特定的语法结构,按照代码的先后顺序,依次执行,程序中大多数的代码都是这样执行的。 \ No newline at end of file