我有一个功课实现一个简单的测试应用程序,下面是我当前的代码:
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循环并打印测试完成,但它不工作,我知道原因可能那个“休息”打破了开关,我该怎么让它打破while循环呢?