mercredi 28 mars 2018

My 'if' statements are being totally skipped in Java. How can I get them to be acknowledged? What is the issue?

import java.util.Scanner;

public class Class_3_26 {

public static void type() {
    System.out.println("Student or Teacher?");
    Scanner input = new Scanner(System.in);
    String userInput = input.next();
    if (userInput == "Student") {
        student("Jono", 12);
    }
    if (userInput == "Teacher") {
        teacher("Mr. Fomenko", "Technology");
    }
    else {
        System.out.println("DOES NOT COMPUTE");
        System.out.println("TRY AGAIN");
        type();
    }
}

public static void student(String name, int grade) {
    System.out.println(name + " is a student at Waterford High School. This person is in grade " + grade + ".");
}

public static void teacher(String name, String subject) {
    System.out.println(name + " is a teacher at Waterford High School. This person teaches " + subject + "class.");
}



public static void main(String[] args) {
    type();

}

}

So here is my code. I am doing this for a project in class and for some reason, the IFs are just being skipped over. No matter what you input, even if it's "Student" or "Teacher" which should be correct, it prints the else. Any ideas?

Aucun commentaire:

Enregistrer un commentaire