【发布时间】:2015-01-26 17:27:39
【问题描述】:
如何在 Java 中创建选项菜单?这是据我所知:
import java.util.Scanner;
public class Mini {
public static void main(String[] args) {
Scanner enter = new Scanner(System.in);
System.out.println("Select an option: ");
System.out.println(" A. Hat ");
System.out.println(" B. Orange ");
System.out.println(" C. Bounty ");
System.out.println(" D. Exit ");
choice = enter.next(); /* <--what do i put because i use char? */
}
}
我必须使用do-while 的循环。如果我使用 char,我会感到困惑。
【问题讨论】:
-
为什么你认为你需要一个
do while循环?我并不是说我不同意使用一个。我只是好奇需求来自哪里 -
这只是因为我需要选择 a,b,c,d 。如果我使用 d 程序退出。我不确定我是否应该使用 do while 或 if then .. 对不起,我在这里仍然一无所知。
-
你知道如何写一个简单的
while或do while吗?