I have a comp sci project:
Prompt the user to enter a word.
- If the word is “Neil,” then ask the user to enter a letter. If the letter is a or b, display “Peart.” If it’s another letter, display “Xanadu.”
- If the word is “Geddy,” then ask the user to enter a number. If the number is odd and divisible by 9, display “Lee.” If the number is negative or equals 2012, display “YYZ.”
I typed the code for this and everything works except one thing. After I write Neil and it asks me to write a letter, if I type a or b it doesn't output Peart it outputs 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");
}
}
}
}