I am just starting with Java and I have a baffling problem. I have a short piece of code, and somehow my IF statement is skipped over. Here it is:
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! ;-)");
}
}
}
}
Even when I reply "no" , the IF statement is not executed, but the response is captured and shown on screen; Can someone help me with that IF statement,
Thanks!
T