我有一个comp sci项目:
提示用户输入单词。
我为此输入了代码,除了一件事以外,一切都有效。在我写了Neil并且它要我写一封信之后,如果我输入a或b它没有输出Peart它输出Xanadu。
import java.util.Scanner;
public class Rush
{
public static void main()
{
Scanner myReader = new Scanner (System.in);
System.out.print("Enter a word:" );
String word = myReader.nextLine();
if (word.equals ("Neil"))
{
System.out.print("Enter a letter: ");
String letter = myReader.nextLine();
if (letter == "A" || letter == "a" || letter == "B" || letter == "b")
{
System.out.println("Peart");
}
else
{
System.out.println("Xanadu");
}
}
if (word.equals ("Geddy"))
{
System.out.print("Enter a number: ");
int number = myReader.nextInt();
if (number % 2 != 0 && number % 9 == 0)
{
System.out.println("Lee");
}
if (number < 0 || number == 2012)
{
System.out.println("YYZ");
}
}
}
}