永远不要输入if语句。始终是else语句。只需要帮助找出if语句被忽略的原因..我的if语句有问题吗?
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);
}
}