【发布时间】:2020-04-13 20:42:30
【问题描述】:
所以我正在尝试的是,在我通过一项搜索获得足够的结果以转到另一项之后。换句话说,我想退出 switch 语句并返回到 while 循环。我该怎么做?
我有这个作为代码:
public static void main(String[] args) throws FileNotFoundException {
String input = "";
Scanner scan = new Scanner(System.in);
System.out.println("Hello, input witch method you shall use(name, amount or date): ");
input = scan.next();
Warehouse storage = new Warehouse();
//todo while loop kad amzinai veiktu. Ar to reikia ?
while (!input.equals("quit")) {
switch (input) {
case "name":
storage.searchByName();
break;
case "amount":
storage.searchByAmount();
break;
default:
System.out.println("Wrong input!");
}
}
}
【问题讨论】:
标签: java loops while-loop switch-statement exit