此Java代码有什么问题。它在Eclipse中显示“终止的应用程序”

时间:2019-02-20 17:12:43

标签: 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.");

        }
    }
}

1 个答案:

答案 0 :(得分:2)

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