Everything about this code works fine, except the while loop won't end, even when the strings are perfectly matched. Help, please?

import java.util.Scanner;


public class SecretPhrase
{

	public static void main(String[] args)
	{

		System.out.println("Congratulations! You won! Thanks for playing!");
			
		
	} 

}

Recommended Answers

Don't use == or != to compare Strings. Use the equals() method.

Also indent you loops and if() blocks. It makes the program flow much easier to follow.

Jump to Post

All 2 Replies

Don't use == or != to compare Strings. Use the equals() method.

Also indent you loops and if() blocks. It makes the program flow much easier to follow.

commented: Very helpful. +0

That fixed it! Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.