I am making a basic guessing game for my first java test and i have same by an interesting problem. My if statement isn't doing what it is told but when i trace it, the outputs are the same. My Code is... ;
import java.util.Scanner;
public class Game {
public static void main(String[] arg) {
Scanner GetInput = new Scanner(System.in);
try {
String Word;
String Guess;
int attempts = 0;
boolean win = false;
System.out
.println("Hello, and welcome to the guessing game! This game is very simple; one player will enter a word when");
System.out
.println("asked, then the next player will need to guess the word Be warned player two, you only have three guesses");
System.out
.println("Let's get started. Player ONE, please enter you're word: ");
Word = GetInput.next();
System.out
.println("Okay the word has been entered, now player TWO must guess");
do {
Guess = null;
System.out.println("Guess the word: ");
Guess = GetInput.next();
System.out.println(Guess + "/" + Word);
if (Word == Guess) {
System.out.println("You won!");
break;
} else if (Guess != Word) {
attempts ++;
}
if (win == false && attempts == 3) {
System.out.println("You lose!");
break;
}
} while (attempts <= 3);
} finally {
GetInput.close();
}
}
}