while与for的相同:
业绩与旅游,月的天数
package com.operator;
import java.util.Scanner;
public class SwitchCaseDemo {
public static void main(String[] args) {
//提示用户输入业绩排名 int
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你的业绩名次:" );
int num1 = scanner.nextInt();
switch (num1) {
case 1:
System.out.println("欧洲游");
break;
case 2:
System.out.println("亚洲游");
break;
case 3:
System.out.println("国内游");
break;
case 4:
System.out.println("省内游");
break;
default:
System.out.println("游什么游");
}
System.out.println("请输入月份:" );
int num2 = scanner.nextInt();
switch (num2) {
case 1:
System.out.println("31天");
break;
case 2:
System.out.println("28天");
break;
case 3:
System.out.println("31天");
break;
case 4:
System.out.println("30天");
break;
case 5:
System.out.println("31天");
break;
case 6:
System.out.println("30天");
break;
case 7:
System.out.println("31天");
break;
case 8:
System.out.println("31天");
break;
case 9:
System.out.println("30天");
break;
case 10:
System.out.println("31天");
break;
case 11:
System.out.println("30天");
break;
case 12:
System.out.println("31天");
break;
default:
System.out.println("什么玩意?");
}
}
}
跑个圈吧
import java.util.Scanner;
public class WhileDemo02 {
public static void main(String[] args) {
跑圈 跑完一圈提示用户是否还能跑,如果不能则结束
Scanner scanner = new Scanner(System.in);
int i = 1;
while (true) {
System.out.println("你已经跑了第" + i + "圈,是否继续?" );
String str = scanner.next();
if ("否".equals(str)) {
System.out.println("不行了,跑不动了!");
break;
} else if ("是".equals(str)){
System.out.println("加油,你是最棒的");
i++;
}
else {
System.out.println("什么玩意?");
}
}
}
}
九九乘法表