我试图让用户输入是或否(是或否),但我一直遇到并发症。我还必须使小写 y 和 n 起作用。我想知道最好的方法是什么?这是我的程序:
import java.util.Scanner;
public class Homework2 {
public static void main(String args[]) {
System.out.println("\nWould you like to see some healthy weight loss guidelines? (Y or N)");
char decision = (char) System.in.read();
if (decision.equals("Y")) {
System.out.println("\nPlaceholder");
} else if (decision.equals("N")) {
System.out.println("\n");
System.out.println("========================================================");
System.out.println("|| ||");
System.out.println("|| Thank you From Your Friends At ||");
System.out.println("|| Happy Valley Fitness Center! ||");
System.out.println("|| ||");
System.out.println("========================================================");
} else {
System.out.println("\nYou did not enter yes or no, program stopping");
System.out.println("\n");
System.out.println("========================================================");
System.out.println("|| ||");
System.out.println("|| Thank you From Your Friends At ||");
System.out.println("|| Happy Valley Fitness Center! ||");
System.out.println("|| ||");
System.out.println("========================================================");
}
}
}
蝴蝶不菲
相关分类