day5

基本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.并未在程序中找到取整符号?

 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值