0

Just for testing, I have written this very short program:

import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String input = scan.nextLine();
        if (input == "y" ) {
            System.out.println("Test");
        }
    }
}

When I enter y, it does not print anything and just normally finishes with exit code 0.

Is this just the case on my machine? If so, why might this be the case?

Or am I making a mistake here? If so, what do I need to do to fix it?

Thank you very much in advance.

maddingl
  • 197
  • 4
  • 20

1 Answers1

0

Your comparison of strings is where the issue is. Use input.equals("y") instead. See here for details

MisterMystery
  • 402
  • 6
  • 14