How would one go about having the user inputted text equal to a string. If I input "January", I would like the if statement to run and print out "First". However, the else runs instead and "invalid" is printed out.
I have also tried putting single quotes within double quotes just to see if it would work, but it prints out "invalid" as well.
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String inputMonth;
int inputDay;
inputMonth = scnr.next();
if (inputMonth =="January") {
System.out.println("First");
}
else {
System.out.println("invalid");
}
}
}
When I input "January" I expect the output to be "First", but it outputs "invalid".
Aucun commentaire:
Enregistrer un commentaire