dimanche 13 septembre 2020

Cannot get the if/else statement to work in java for my program [duplicate]

import java.util.Scanner;
public class chapter1 {
public static void main(String[] args) {
    Scanner userInput = new Scanner(System.in);
        System.out.print("Enter full name:");
    String name = userInput.nextLine();
        System.out.println("Your assigned name is " + name);
        System.out.println("Would you like to play.Y/N:");
    String answer = userInput.nextLine();
    String yes = "Y";
    String no = "N"
    if (answer==yes) {
        System.out.println("Fantastic, lets begin!");
    } else if(answer==no) {
        System.out.println("Your lost, goodbye!"); 
        System.exit(0);
    }
    
  
    }
}

The if else statement will not print it. i cannot get it to work. please help me fix this problem. I am a beginner learning java.

Aucun commentaire:

Enregistrer un commentaire