Java_Switch


import
java.util.Scanner; public class Switch_test{ public static void main(String[] agrs){ float score; Scanner input = new Scanner(System.in); while (true) { System.out.print("请输入你的成绩:"); score = input.nextFloat(); if (score<0||score>100){ System.out.println("请输入百分制成绩!!!!"); } else { int a=(int)score/10; switch(a){ case 10 : System.out.println("A"); break; case 9 : System.out.println("A"); break; case 8 : System.out.println("B"); break; case 7 : System.out.println("C"); break; case 6 : System.out.println("D"); break; default : System.out.println("不及格"); break; } } } } }

Java的switch用法基本和C语言一致

posted @ 2018-07-30 19:17  王学长  阅读(125)  评论(0编辑  收藏  举报