- if条件语句
public class Example07 {
public static void main(String[] args) {
int x=5;
if(x<10) {
x++;
}
System.out.println(x);
}
}
- if…else语句
public class Example08 {
public static void main(String[] args) {
int num=19;
if(num%2==0) {
System.out.println("num是一个偶数");
}else {
System.out.println("num是一个偶数");
}
}
}
- if…elseif…else
public class Example09 {
public static void main(String[] args) {
int chengji=75;
if(chengji>80){
System.out.println("优");
}else if(chengji>70){
System.out.println("良");
}else if(chengji>60){
System.out.println("合格");
}else {
System.out.println("合格");
}
}
}
- switch条件语句
public class Example10 {
public static void main(String[] args) {
int week=5;
switch(week){
case 1:
System.out.println("星期一");
break;
case 2:
System.out.println("星期二");
break;
case 3:
System.out.print("星期三");
break;
case 4:
System.out.print("星期四");
break;
case 5:
System.out.print("星期五");
break;
case 6:
System.out.print("星期六");
break;
}
}
}