代码如下:
import java.util.*;
public class day730 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int choice = in.nextInt();
int a = 0;
switch (choice) {
case 1:
System.out.println("999");
break;
case 2:
System.out.println("9999999");
break;
default:
System.out.println("please enter again");
a = 1;
break;
}
in.close();
}
}
这是不带循环的,能正常输出999 或9999999
import java.util.*;
public class day730 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int choice = in.nextInt();
int a = 0;
while (a == 1) {
switch (choice) {
case 1:
System.out.println("999");
break;
case 2:
System.out.println("9999999");
break;
default:
System.out.println("please enter again");
a = 1;
break;
}
}
in.close();
}
}
这是带循环的,运行输入1或2都只是输出一个空行就结束了程序
代码在vscode上用coderunner运行的,本人刚开始学习Java 轻点喷,ballball各位了