首页 > 解决方案 > java.lang.Error 我在代码中遗漏了什么吗?

问题描述

如果有人知道我为什么会遇到此错误,这只是一个简单的查询,我将不胜感激。

问题是简单的 java if else if else 循环问题。

所以我试图使语法尽可能正确。下面的代码是我正在执行的代码。

 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);
        }
    }
}

我得到的错误就是这个。

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

at ifelseloop.main(ifelseloop.java:2)

标签: javaloopside

解决方案


推荐阅读