控制流程

一,顺序流程
二,分支流程


1,if (){
}
else if(){
}
else{
}


2,switch(num){
case ...:
break;
case ...:
break;
default:
}

 

注:

1,如果case中没有加break,则会出现穿透效果

num的类型只能是int、byte、short、char、String、枚举

在jdk7之前的版本中不支持String


2,break结束执行循环时,默认结束是最近的循环


3,continue结束当前循环,进入下一次循环

 

三,循环流程


1,while 执行0~n次
2,do...while 执行1~n次
3,for 执行0~n次


注:

1,使用while时别忘了n++

2, ==只能正确的比较基本数据类型是否相等
字符串判断不能用"==", 需要用equals方法
if("admin" == name && "123" == password)


3,

if(score >= 90){
System.out.println("A");
}else if(80 <= score < 90){
System.out.println("B");
}else if(60 <= score < 80){
System.out.println("C");
}else{
System.out.println("D");
}错误,语法不正确
应该:if(score <=100 && score >= 90){
System.out.println("A");
}else if(80 <= score && score < 90){
System.out.println("B");
}else if(60 <= score && score < 80){
System.out.println("C");
}else if(0 <= score && score < 60){
System.out.println("D");
}else{
System.out.println("您输入的分数正确,请输入0~100之间的整数");
}

 





posted @ 2018-10-11 14:12  小荀令  阅读(172)  评论(0)    收藏  举报