Never enters the if statement. Always the else statement. Just need help to find out why the if statement is being ignored.. is something wrong with my if statement?
import java.util.Random;
import java.util.*;
public class WordGameRandom {
public static void main(String[] args)
{
//sets the number of arraies and their values
String[] words = {"Cat", "Pig", "Dog", "Rat"};
int Max = 4;
int x = 1;
String guess;
Scanner input = new Scanner(System.in);
do{
System.out.print("Please guess a three letter animal: ");
guess = input.nextLine();
System.out.println("Your word:" + guess);
Random random = new Random();
System.out.println("The computers word: " +
words[random.nextInt(words.length)]);
if(guess == words[random.nextInt(words.length)])
{
System.out.println("Congrats!");
++x;
}
else
{
System.out.println("Fail");
}
}
while(x != 2);
}
}