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!!