代码将编译,但我的菜单似乎有错误。The user will select one of the choices and the program should execute, but When choosing a selection nothing happens. 这是代码:
import java.util.Scanner;
class Tutorial{
public static void main(String args[]){
Geek myGeek = new Geek("Geek");
System.out.println("Command Options: ");
System.out.println("a: Geek's Name");
System.out.println("b: Num Questions Asked");
System.out.println("c: All Numbers Are the Same");
System.out.println("d: Sum Between Two Integers");
System.out.println("e: Repeat the String");
System.out.println("f: It is Palindrome");
System.out.println("?: Display");
System.out.println("q: Quit");
Scanner scan = new Scanner(System.in);
String choice = scan.nextLine();
do {
switch (choice){
case "a":
myGeek.getName();
break;
case "b":
myGeek.getnumberofQuestions();
break;
case "c":
System.out.println("Enter the first number");
int input1 = scan.nextInt();
System.out.println("Enter the second number");
int input2 = scan.nextInt();
System.out.println("Enter the third number");
int input3 = scan.nextInt();
myGeek.allTheSame(input1, input2, input3);
break;
case "d":
System.out.println("Enter the first number");
int num1 = scan.nextInt();
System.out.println("Enter the second number");
int num2 = scan.nextInt();
myGeek.sum(num1, num2);
break;
case "e":
System.out.println("Enter a string: ");
String word1 = scan.nextLine();
System.out.println("Enter an integer: ");
int numberOfTimes = scan.nextInt();
System.out.println("Enter the third number");
myGeek.repeat(word1, numberOfTimes);
break;
case "f":
System.out.println("Enter a string: ");
String word2 = scan.nextLine();
myGeek.isPalindrome(word2);
break;
case "?":
System.out.println("Command Options: ");
System.out.println("a: Geek's Name");
System.out.println("b: Num Questions Asked");
System.out.println("c: All Numbers Are the Same");
System.out.println("d: Sum Between Two Integers");
System.out.println("e: Repeat the String");
System.out.println("f: It is Palindrome");
System.out.println("?: Display");
System.out.println("q: Quit");
break;
} }while (choice != "q");
}
}
这是运行时的样子: