我有一个实现简单测试应用程序的作业,下面是我当前的代码:
import java.util.*;
public class Test{
private static int typing;
public static void main(String argv[]){
Scanner sc = new Scanner(System.in);
System.out.println("Testing starts");
while(sc.hasNextInt()){
typing = sc.nextInt();
switch(typing){
case 0:
break; //Here I want to break the while loop
case 1:
System.out.println("You choosed 1");
break;
case 2:
System.out.println("You choosed 2");
break;
default:
System.out.println("No such choice");
}
}
System.out.println("Test is done");
}
}
我现在想做的是,当按下 0
,这意味着用户想退出测试,然后我打破 while loop
和打印 Test is done
,但它不是这样工作的,我知道原因可能是 "break"
打破 switch
,我怎么能让它打破 while loop
而不是?