import java.util.Scanner;
public class Assignment6 {
public static void commandList()
{
System.out.println("Command Options------------");
System.out.println("a: Create a new table");
System.out.println("b: Change the row sizes");
System.out.println("c: Change the column sizes");
System.out.println("d: Change the data types");
System.out.println("e: Change the formats");
System.out.println("f: Display the table");
System.out.println("g: Display the log data");
System.out.println("?: Display this menu");
System.out.println("q: Quit the program");
System.out.println("---------------------------");
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Command Options------------");
System.out.println("a: Create a new table");
System.out.println("b: Change the row sizes");
System.out.println("c: Change the column sizes");
System.out.println("d: Change the data types");
System.out.println("e: Change the formats");
System.out.println("f: Display the table");
System.out.println("g: Display the log data");
System.out.println("?: Display this menu");
System.out.println("q: Quit the program");
System.out.println("---------------------------");
String input = "";
System.out.println("Please input a command:");
input = in.nextLine();
do
{
if (input.equals("a"))
{
System.out.println("a [Input three integers to ititialze a table:] ");
int newTable = in.nextInt();
}
else if (input.equals("b"))
{
System.out.println("Change the row sizes");
int newRow = in.nextInt();
}
else if (input.equals("c"))
{
System.out.println("c [Type an integer to update the table column]: ");
int newColumn = in.nextInt();
}
else if (input.equals("d"))
{
System.out.println("d [Type an integer to update the data type]: ");
int newDataType = in.nextInt();
}
else if (input.equals("e"))
{
System.out.println("e [Type and integer to update printf format]: ");
int newPrintf = in.nextInt();
}
else if (input.equals("f"))
{
System.out.println("f [Display the table]");
}
else if (input.equals("g"))
{
System.out.println("g [Display the log data]");
}
else if (input.equals("?"))
{
commandList();
}
else
{
System.out.println("Invalid ***Type ? to get commands***");
}
}
while (!input.equals("q"));
{
}
}
}
我创建了一个菜单,我要求用户输入一个字母,程序将显示他们选择的命令选项。现在我有它,所以如果用户输入“a”,那么将输出“输入三个整数来初始化表格”。我需要它然后打印“请输入命令”接下来,但它只是不断打印“输入三个整数itialize表”我一直在尝试不同的方法一段时间了,我不知道该怎么做。任何帮助?如何在java中使用if-else语句获取多个用户输入。
如果你想让用户给你另一个'输入',把输入'input'的语句放到循环中,而不是外部。 – ajb