From e4fa01b82465b831d5dcb3c356c44f3502a7c546 Mon Sep 17 00:00:00 2001 From: pj3q7x5mz <1732875197@qq.com> Date: Thu, 17 Nov 2022 11:22:39 +0800 Subject: [PATCH] ADD file via upload --- Java入门(第四章)- 分支结构.txt | 215 ++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 Java入门(第四章)- 分支结构.txt diff --git a/Java入门(第四章)- 分支结构.txt b/Java入门(第四章)- 分支结构.txt new file mode 100644 index 0000000..53a1aac --- /dev/null +++ b/Java入门(第四章)- 分支结构.txt @@ -0,0 +1,215 @@ +1.Java分支结构之 if...else +package step2; + +import java.util.Scanner; + +public class HelloIfStep2 { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + /******start******/ + int score; + System.out.println("请输入学员成绩:"); + score=input.nextInt(); + if(score>=85 && score<=100) + { + System.out.print("优,非常棒!"); + } + else + { + System.out.print("良,下次加油!"); + } + + + + + /******end******/ + } +} +2.Java分支结构之Switch +package step4; + +import java.util.Scanner; + +public class HelloSwitch { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + System.out.println("请输入月份:"); + + int input = sc.nextInt(); //获取输入的月份 + + //通过输入的月份来判断当前季节并输出 + /*****start*****/ + int season; + switch(input) + { + case 1: + System.out.print("1月是冬天"); + break; + case 2: + System.out.print("2月是冬天"); + break; + case 3: + System.out.print("3月是春天"); + break; + case 4: + System.out.print("4月是春天");break; + case 5: + System.out.print("5月是春天"); + break; + case 6: + System.out.print("6月是夏天"); + break; + case 7: + System.out.print("7月是夏天"); + break; + case 8: + System.out.print("8月是夏天"); + break; + case 9: + System.out.print("9月是秋天"); + break; + case 10: + System.out.print("10月是秋天"); + break; + case 11: + System.out.print("11月是秋天"); + break; + case 12: + System.out.print("12月是冬天"); + break; + } + + + /*****end*****/ + + } +} +3.Java分支结构之多重if +package step3; + +import java.util.Scanner; + +public class HelloStep3 { + public static void main(String[] args) { + System.out.println("星级成绩评定系统"); + System.out.println("请输入成绩:"); + Scanner sc = new Scanner(System.in); + /******start******/ + int score; + score=sc.nextInt(); + if(score>=90&&score<=100) + { + System.out.print("*****五星成绩"); + } + else if(score<90&&score>=80) + { + System.out.print("****四星成绩"); + } + else if(score<80&&score>=70) + { + System.out.print("***三星成绩"); + + } + else if(score<70&&score>=60) + { + System.out.print("**俩星成绩"); + } + else if(score<60) + { + System.out.print("无星成绩"); + } + + + + + /******end******/ + } +} +4.来吧,我是BOSS! +package step5; + +import java.util.Scanner; + +public class Practice { + + final static Scanner sc = new Scanner(System.in); //创建扫描仪 + + //第一题 + public void first(){ + System.out.println("请输入人数:"); + int input = sc.nextInt(); //获取输入的数据 + + /*****start*****/ + + if (input<10) + { + System.out.println("打半场"); + } + else + { + System.out.println("打全场"); + } + + + + /*****end*****/ + } + + //第二题 + public void second(){ + System.out.println("请输入今天星期几:"); + int input = sc.nextInt(); //获取输入的数据 + + /*****start*****/ + if (input==1) + { + System.out.println("今天吃米饭"); + } + else if(input==2) + { + System.out.println("今天吃牛排"); + } + else if(input==3) + { + System.out.println("今天吃鸡排"); + } + else + { + System.out.println("今天吃红烧肉"); + } + + + + + /*****end*****/ + } + + //第三题 + public void third(){ + System.out.println("请输入今天星期几:"); + int input = sc.nextInt(); //获取输入的数据 + + /*****start*****/ + switch (input) + { + case 1: + System.out.println("今天吃米饭"); + break; + case 2: + System.out.println("今天吃牛排"); + break; + case 3: + System.out.println("今天吃鸡排"); + break; + default: + System.out.println("今天吃红烧肉"); + break; + + } + + + + /*****end*****/ + } +}