基本Switch语句
package test;
public class SwitchStatement {
public static void main(String args[]){
scoreToLevelTest();
}//Of main
public static char scoreToLevel(int paraScore){
\\paraScore为虚假宣传,真正运行时带入main触发的tempScore计算
char resultLevel = 'E';
//char 用于表示一个字符
//char本质上是一个固定占用两个字节的无符号正整数,对应Unicode编号
//switch语句可以拥有多个 case语句,每个 case后面跟一个要比较的值和冒号
int tempDigitalLevel = paraScore / 10;
switch (tempDigitalLevel){
case 10:
//case表示分支,当传入值等于case的值时,就执行case后语句
case 9:
resultLevel = 'A';
break;
//遇到 break语句时,switch语句终止,程序跳转至后面语句运行
case 8:
resultLevel = 'B';
break;
case 7:
resultLevel = 'C';
break;
case 6:
resultLevel = 'D';
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
resultLevel = 'F';
break;
default:
resultLevel = 'E';
}//Of Switch
return resultLevel;
}//Of scoreToLevel
public static void scoreToLevelTest(){
int tempScore = 100;
System.out.println("Score " + tempScore + " to level is:" + scoreToLevel(tempScore));
tempScore = 91;
System.out.println("Score " + tempScore + " to level is:" + scoreToLevel(tempScore));
tempScore = 82;
System.out.println("Score " + tempScore + " to level is:" + scoreToLevel(tempScore));
tempScore = 75;
System.out.println("Score " + tempScore + " to level is:" + scoreToLevel(tempScore));
tempScore = 66;
System.out.println("Score " + tempScore + " to level is:" + scoreToLevel(tempScore));
tempScore = 52;
System.out.println("Score " + tempScore + " to level is:" + scoreToLevel(tempScore));
tempScore = 8;
System.out.println("Score " + tempScore + " to level is:" + scoreToLevel(tempScore));
tempScore = 120;
System.out.println("Score " + tempScore + " to level is:" + scoreToLevel(tempScore));
}//Of scoreToLevelTest
}//Of class SwitchStatement
question:
1.为什么命名中score首字母并不大写?看起来并不与para、temp平级
2.为什么赋值不在main中进行?感觉上更直观
3.并未在程序中找到取整符号?