0
package mygame;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String nome;

        nome = scan.nextLine();

        if(nome == "1") {
            System.out.println("It worked");

        }

        scan.close();
    }
}

I'm trying to understand why my IF is not working. I'm using Scanner to get any information but no matter what my IF doesn't work.

Felnin
  • 1
  • I'm using Eclipse IDE, btw. – Felnin Jan 19 '20 at 22:02
  • 1
    Can you edit **IF** to **if**? if is not an acronym but you're capitalizing it as if it were and it's confusing. – CausingUnderflowsEverywhere Jan 19 '20 at 22:09
  • 4
    Your string comparison is flawed: == (double equals) compares references to see if they are the same, not the content of those references. `nome.equals("1")`, will compare the actual content of the strings. – otoomey Jan 19 '20 at 22:10
  • click next to the line number on the line that has if(nome == "1") { and debug your application. The program will pause when it reaches that line, then you can investigate the value of the variable nome. – CausingUnderflowsEverywhere Jan 19 '20 at 22:12

0 Answers0