So I'm incredibly new to java and coding in general. I've been asked to code a program that asks the user a riddle and responds with "Correct!" or "Wrong!" depending on the answer. I thought an if else if statement would do the trick but it is not returning the desired results. the answers "man" or "a man" are both considered correct(and capitalization does not matter Ex "mAn" would still be right, but "man!" would not).
import java.util.Scanner;
public class HW3 {
public static void main(String[] args) {
System.out.print("What walks on four legs in the morning, two legs in the afternoon, and three legs in the evening? ");
Scanner input = new Scanner(System.in);
String Answer = input.next();
if(Answer.equals("man"))
System.out.println("Correct!");
else
System.out.println("Wrong!");
if (Answer.equals("a man"))
System.out.println("Correct!");
else
System.out.println("Wrong!");
}
}
Aucun commentaire:
Enregistrer un commentaire