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",Please fix the problem for me.
Expand|Select|Wrap|Line Numbers
- 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"???