java - 这段java代码有什么问题。 Eclipse 中显示 "Terminated Application"

标签 java if-statement

package javagain;

public class Gender_interest {
    public static void main(String args[]) {

        if((args[0] == "Female") && (Integer.parseInt(args[1])>=1) && (Integer.parseInt(args[1])<=58)) {
            System.out.println("Percentge of Interest is 8.2%");
        }

        else if((args[0] == "Male") && (Integer.parseInt(args[1])>=1) && (Integer.parseInt(args[1])<=58)) {
            System.out.println("Percentge of Interest is 8.4%");
        }

        else if((args[0] == "Female") && (Integer.parseInt(args[1])>=59) && (Integer.parseInt(args[1])<=100)) {
            System.out.println("Percentge of Interest is 9.2%");
        }

        else if((args[0] == "Male") && (Integer.parseInt(args[1])>=59) && (Integer.parseInt(args[1])<=100)) {
            System.out.println("Percentge of Interest is 10.5%");
        }

        else {
            System.out.println("Enter correct values.");

        }
    }
}

最佳答案

这里(args[0] == "Female")是错误的,在java中==检查将保存这些字符串(对象)的内存位置。您应该使用 (args[0].equals("Female")) 或 (args[0].equalsIgnoreCase("Female"))

关于java - 这段java代码有什么问题。 Eclipse 中显示 "Terminated Application",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54791899/

相关文章:

java - 如何实现 "recycle bin"功能?

java - 匹配字符串可选结尾的正则表达式

java - 显示 AlertDialog 的方法似乎乱序执行

mysql - 测试表是否存在

java - 否则没有if?

PHP:数组里面有一个if语句

C++ - 为什么程序在映射迭代器中使用 if 语句崩溃?

java - Java 两点之间角度的数学计算

java - 错误 java.lang.RuntimeException : Unable to start activity

python - `object in list` 的行为与 `object in dict` 不同?