我是一名学生,目前正在使用java,我很难编程高和低猜谜游戏。我不能使用循环或“while”代码。有什么想法吗?这是我现在所拥有的:高或低游戏没有循环或“while”代码
public class FinalProject1
{
public static void main(String [] args)
{
System.out.println("Number Guessing Game 1-1000\nGuess a number");
guess();
}
public static int random()
{
int x = (int)(1000*Math.random() + 1);
return x;
}
public static void guess()
{
int num = random();
int tries = 0;
Scanner keyboard = new Scanner(System.in);
String inputString = keyboard.nextLine();
int input = Integer.parseInt(inputString);
if (input > num)
{
System.out.println("Guess a higher number");
inputString = keyboard.nextLine();
}
else if (input < num)
{
System.out.println("Guess a lower number");
inputString = keyboard.nextLine();
}
else if (num == input)
{
System.out.println("You Win");
}
}
}
如果你不理解递归从一开始读这句话。 –
@ElliottFrisch并单击[这里](https://stackoverflow.com/questions/44267747/high-or-low-game-without-looping-or-while-code)了解更多:) –