if,switch控制语句。for循环语句,终断,跳过。

if控制语句
public static void main(String[] args) {

/**
 * if控制语句
 * 列举学生成绩,
 */
int crose = 86;//满分100
//成绩在90~100
if(crose>90){
	System.out.println("优秀");
}else //成绩在75~90
	if(crose>=75){
	System.out.println("良好");
}else //成绩在60~75
	if(crose>=60){
	System.out.println("及格");
}else{
	//60分以下
	System.out.println("不及格");
}

}

输出结果:良好

switch控制语句
public static void main(String[] args) {

/**
 * switch控制语句
 * 这个语句方便写对应条件的语句,比如一年之中有四个季节,12个月,三个月对应一个季节
 */
int month = 6;
switch(month){
case 12:
	System.out.println("冬天");
	break;
case 1:
	System.out.println("冬天");
	break;
case 2:
	System.out.println("冬天");
	break;
case 3:
	System.out.println("春天");
	break;
case 4:
	System.out.println("春天");
	break;
case 5:
	System.out.println("春天");
	break;
case 6:
	System.out.println("夏天");
	break;
case 7:
	System.out.println("夏天");
	break;
case 8:
	System.out.println("夏天");
	break;
case 9:
	System.out.println("秋天");
	break;
case 10:
	System.out.println("秋天");
	break;
case 11:
	System.out.println("秋天");
	break;
default:
	System.out.println("请输入正确月份");
	break;
}

}

输出结果:夏天

for循环语句,终断,跳过
public static void main(String[] args) {
/**
* for循环语句
* 循环次数7次
/
for(int i=1;i<=7;i++){
System.out.println(“hello work!!”);
}
System.out.println("–over–");
System.out.println(“循环终断,第3次终断”);
/
*
* 循环终断
*/
for(int i=1;i<=7;i++){
if(i==3){
break;
}
System.out.println(“hello work!!”);
}
System.out.println("–over–");
System.out.println(“循环跳过,第4次跳过”);

	/**
	 * 循环跳过
	 */
	for(int i=1;i<=7;i++){
		if(i==4){
			continue;
		}
		System.out.println("hello work!!");

}
}
输出结果
hello work!!
hello work!!
hello work!!
hello work!!
hello work!!
hello work!!
hello work!!
–over–
循环终断,第3次终断
hello work!!
hello work!!
–over–
循环跳过,第4次跳过
hello work!!
hello work!!
hello work!!
hello work!!
hello work!!
hello work!!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值