У меня есть домашняя работа по внедрению простого тестового приложения, ниже мой текущий код:
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
вместо этого?