1.if语句
public class test01 {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入两个数字");
int a = scanner.nextInt();
int b = scanner.nextInt();
if (a > b) {
System.out.println(a + "大于" + b);
} else if (a == b) {
System.out.println(a + "等于" + b);
} else {
System.out.println(a + "小于" + b);
}
}
}
2.switch
public class test01 {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一个数字");
int a = scanner.nextInt();
switch (a) {
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;
default:
System.out.println("错误");
}
}
}
3.for循环
public class test01 {
public static void main(String args[]) {
for (int i = 0; i <10 ; i++) {
System.out.println(i);
}
}
}
4.while循环
public class test01 {
public static void main(String args[]) {
int i = 0;
while (i < 10) {
System.out.println(i);
i++;
}
}
}
5.do-while循环
public class test01 {
public static void main(String args[]) {
int i = 0;
do {
System.out.println(i);
i++;
} while (i < 10);
}
}