所以我有这个程序,我正在努力建立,这是一个简单的足球比赛。令我困惑的唯一问题是如何让我的程序循环遍历所有这些问题。底部的JOptionPane消息不合适,我的代码有点凌乱我只是想知道是否有人可以帮助我如何让我的程序循环通过所有这些问题并让用户结束它。
package football;
import javax.swing.JOptionPane;
public class Football {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Are you ready for some FOOTBALL?!?!?!");
String StringTeamOption = JOptionPane.showInputDialog("Pick two of the four teams");
//Input my methods
String StringBallOption = JOptionPane.showInputDialog("Who has the ball first?");
//If statement and loop
String StringPlayOption = JOptionPane.showInputDialog("Did the team pass or run the ball?");
//If statement and part of loop
String StringYardage = JOptionPane.showInputDialog("How far did the team throw/run?");
//If statement and calculation also part of loop
String StringScoreingPlay = JOptionPane.showInputDialog("Did the team score?");
//If statement and part of loop
String StringPlayAgain = JOptionPane.showInputDialog("Do you want to play again");
//loop
JOptionPane.showMessageDialog(null, "The ball is on the 20 yard line anything over 80 yards will not count");
JOptionPane.showMessageDialog(null, "End of the quarter!");
JOptionPane.showMessageDialog(null, "End of the game!!!");
//Messages for explanation
答案 0 :(得分:0)
你可以创建一个布尔标志和while或while while循环吗?
Boolean keepPlaying = true;
while (keepPlaying) {
// ... All the questions here.
//If input from "Do you want to play again?" is no, set keepPlaying to false.
}