dimanche 13 octobre 2019

Can you help me with this if/else statement? [duplicate]

This question already has an answer here:

**CODE:**

import java.io.*;
class test
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Number");
        String n=br.readLine();
        if (n=="0"){
            System.out.println("true");
        }
        else{
            System.out.println("false");
        }
    }
}


**OUTPUT:**

Number
0 //entered by user
false

**EXPECTED ANSWER:**

true

This output is suppose to be true because the number that I entered is 0 and according to the if statement it satisfies the condition yet it doesn't shoe true instead is shows false. [enter image description here][1]

[1]: https://i.stack.imgur.com/mqcNW.jpg here is the image of the program and output.

Aucun commentaire:

Enregistrer un commentaire