如果语句被忽略 - java

时间:2017-08-08 09:40:20

标签: java

我刚刚开始使用Java,我遇到了一个令人困惑的问题。 我有一小段代码,不知怎的,我的IF语句被跳过了。 这是:

import java.util.Scanner;

public class helloworld {

private static Scanner s;

public static void main(String[] args) {

    s = new Scanner(System.in);

    //Question what's your name + validation
        System.out.println("Hello guy, What's your name?");
        String name = s.nextLine();
        System.out.println("Are you ok for " + name + "? (answer by yes or no)");

        String ok = s.nextLine();

// capture ok response and print to screen to show that value is read
        System.out.println(ok); 

// below is ignored!
                if(ok=="no")
                {
                System.out.println("What do you mean? You don't know your name? Bye!");
                }

                if(ok=="yes")
                {
                System.out.println("thank's " + name + "I have a question...");
                    System.out.println("Is my first program good?");
                        String goods = s.nextLine();
                                //validation question programme
                            if(goods=="no")
                            {
                                System.out.println("so i will update my performance!");
                            }
                            if(goods=="yes")
                            {
                                System.out.println("thank you for your answer guy! ;-)");
    }           
    }                   
}
}

即使我回复"没有" ,IF语句没有执行,但是响应被捕获并显示在屏幕上; 有人可以用IF语句帮助我,

谢谢!

Ť

0 个答案:

没有答案