【发布时间】:2015-07-13 12:39:54
【问题描述】:
当输入为5 时,我想终止我的程序。
我的程序在按 5 时没有关闭。
代码 sn-p:
System.out.println("What do you want to do?");
System.out.println("1. Go north");
System.out.println("2. Go east");
System.out.println("3. Go south");
System.out.println("4. Go west");
System.out.println("5. Quit");
System.out.print("Enter command (1-5): ");
// get and return the user's selection
System.exit(0); // exit the menu
return s.nextInt();
如何更改它有什么建议?
【问题讨论】:
-
return s.nextInt();--> 是无法访问的代码 -
你知道
System.exit(0)是做什么的吗? -
其实我试过 System.exit(5);但是很困惑
-
@Nachinne_Manche 这个评论让我发笑。说真的,你试过
if-statement 吗? -
试过了,但没成功...你能帮我做吗?