条件语句
if-else if
/*
判断成绩好坏
0-60 不及格
60-80 及格
80-90 良好
90-100 优秀
*/
//if语句
int score = 75;
if (score>0 && score<=60){
System.out.println("不及格");
}else if (score>60 && score<=80){
System.out.println("及格");
}else if(score>80 && score<=90){
System.out.println("良好");
}else if (score>90 && score<=100){
System.out.println("优秀");
}else {
System.out.println("成绩不符合要求!");
}
switch
/*
判断工作日与非工作日
*/
int day = 6;
switch (day){
case 1:
case 2:
case 3:
case 4:
case 5:
System.out.println("今天是工作日");
break;
case 6:
case 7:
System.out.println("今天是周末");
break;
default:
System.out.println("输入的日期不符合规定!");
}
循环语句
for语句
//for语句
for (int j=0;j<10;j++){
System.out.println("hello world");
i++;
}
foreach语句
//foreach语句
int[] value={0,1,2,3,4,5,6,7,8,9};
for(int k : value) {
System.out.println("hello world"+k);
}
while语句
/*
打印10个hello world
*/
//while语句
int i = 0;
while (i<10){
System.out.println("hello world");
i++;
}
do-while语句
//do-while语句
i=0;
do{
System.out.println("hello world");
i++;
}while (i<10);