标签:
switch(expression){ case value : //Statements break; //optional case value : //Statements break; //optional //You can have any number of case statements. default : //Optional //Statements }以下规则适用于switch语句:
public class Test { public static void main(String args[]){ //char grade = args[0].charAt(0); char grade = 'B'; switch(grade) { case 'A' : System.out.println("Excellent!"); break; case 'B' : case 'C' : System.out.println("Well done"); break; case 'D' : System.out.println("You passed"); case 'F' : System.out.println("Better try again"); break; default : System.out.println("Invalid grade"); } System.out.println("Your grade is " + grade); } }
编译并运行上面使用各种命令行参数的程序。这将产生以下结果:
Well done
Java技术_Java千百问(0018)_switch如何使用
标签:
原文地址:http://blog.csdn.net/ooppookid/article/details/51042786