【发布时间】:2020-10-31 08:18:00
【问题描述】:
我目前是一名高中生,我正在做一个简短的问答游戏作为一个项目。我想知道您是否可以添加多个问题。这是代码
import java.util.Scanner;
import java.util.Random;
public class Quiz
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
Random r = new Random();
int lives = 3;
String answers;
while (lives > 0)
{
System.out.println("Question Goes Here: ");
answers = s.nextLine();
if (answers.equalsIgnoreCase("Answer"))
{
System.out.println("Correct! Please press ENTER to continue");
s.nextLine();
}
//TO-DO IF THE ANSWER IS WRONG
else
{
--lives;
System.out.println("You have " + lives + " lives left");
}
}
//TO-DO IF "LIVES" IS EQUAL TO 0
if (lives == 0)
{
System.out.println("Game Over");
}
}
【问题讨论】:
-
您可以在数组中添加任意数量的问题,然后从那里获取它们
标签: java