即使我输入正确的名称,字符串fName也会显示“ Wrong person”

时间:2019-07-14 00:47:58

标签: java

下面是apples.java,其中有字符串fName = input.nextLine();

class apples {

public static void main(String args[]) {

    Scanner input = new Scanner(System.in);
    Yeet YeetObject = new Yeet();

    System.out.println("Hello user!, please enter your first name: ");
    String fName = input.nextLine();

    YeetObject.firstName(fName);
    }
}

下面是Yeet.java,它的意思是说“你好,亚历山大”而不是“错误的人”

public class Yeet {
public void firstName(String fName) {
    if (fName == "Alexander") {
        System.out.println("Hello, " + fName);
    } else {
        System.out.println("Wrong Person!!!");
    }
}

0 个答案:

没有答案