if else 语句返回错误答案

问题描述 投票:0回答:1
import java.util.Scanner;
public class orOperator {
    public static void main(String args[]) {
        System.out.println(" This code is to check you are eligible or not");
        Scanner buddha2 = new Scanner(System.in);
        System.out.println("Please enter your nationality");
        String nationality = buddha2.nextLine();
        System.out.println("you are " + nationality);
        if (nationality == "indian") {
            System.out.println("you are eligible to join the indian army");
        } else {
            System.out.println("Your are not eligible to join the army");
        }
    }

}

///else 部分返回答案而不是 if 部分// ///座右铭是把国籍作为输入,然后就能得到结果作为国籍 ///

java maven conditional-statements maven-2 maven-plugin
1个回答
0
投票

尝试

if (nationality.equals("indian"))
© www.soinside.com 2019 - 2024. All rights reserved.