mardi 27 juillet 2021

Even though i type in the correct answer for if, it shows me the answer for else

I'm a beginner and have a small problem. The code below should print out "Good" if the user puts in the right answer. But even if I write in the correct word it still uses the else answer

import java.util.Scanner;

public class Program
{
    public static void main(String[] args) {
       Scanner eingabe = new Scanner(System.in);
       
       String antwort = eingabe.nextLine();
    
    'If the answer is "yes" it should print out "Good"'

    if(antwort=="yes") {
        System.out.print("Good");
    } else {
        System.out.print("Bad");
    }
    
    
    }


}

Aucun commentaire:

Enregistrer un commentaire