Hi,
This program prints Hi and ask the user "Print again" if user types"yes" the program should priny "Hi" and ask the question again.
This is the code I wrote,for some reason the program does nothing when the user enter "yes",Pleas e fix the problem for me.
my friend said I should change while(again=="y es") to again.equals("y es")
Why should I do that?Why does not java like again=="yes"???
This program prints Hi and ask the user "Print again" if user types"yes" the program should priny "Hi" and ask the question again.
This is the code I wrote,for some reason the program does nothing when the user enter "yes",Pleas e fix the problem for me.
Code:
import java.util.Scanner;
public class sample
{
public static void main(String [] args)
{
String again;
do{
System.out.println("Hello");
Scanner in=new Scanner(System.in);
System.out.println("Print again???");
again=in.next();
}
while(again=="yes");
}
}
Why should I do that?Why does not java like again=="yes"???
Comment