From ee50af9f807f13c66dad5fedc3aae71dfabdb12a Mon Sep 17 00:00:00 2001 From: pj3q7x5mz <1732875197@qq.com> Date: Thu, 17 Nov 2022 11:21:34 +0800 Subject: [PATCH] ADD file via upload --- Java分支结构.txt | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Java分支结构.txt diff --git a/Java分支结构.txt b/Java分支结构.txt new file mode 100644 index 0000000..d2dd461 --- /dev/null +++ b/Java分支结构.txt @@ -0,0 +1,101 @@ +1.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******/ + } +} +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*****/ + + } +}