java.lang.Error am i missing something in the code?

Viewed 58

This is just a simple query if anyone knows why I am facing this error I would appreciate the help.

The problem is simple java if else if else loop problem .

so I tried to make syntax as correct as possible. The code here below is the one I am executing.

 public class ifelseloop {
 
    public static void main(String[] args){
    
        //  int a = 20;
        //  int b = 20;
    
        String city = "Delhi";
    
        if (city == "madras") {
            System.out.println("the city is not delhi its madras");
        }else if(city == "chennai") {
            System.out.println("the city is not delhi its chennai");
        }else if(city == "bartar") {
            System.out.println("the city is bartar");
        }else {
            System.out.println(city);
        }
    }
}

and the error that I am getting is this.

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at ifelseloop.main(ifelseloop.java:2)
0 Answers
Related