我正在製作Craps java程序,並且在添加「您想再次播放」語句時遇到了一些麻煩。如果你能幫助我,那將不勝感激!此外,我必須計算用戶贏/輸的遊戲數量不正常。如果您發現問題,請告訴我!需要幫助在我的程序中添加「您想再次播放」語句
import java.util.Scanner;
public class Lab5 {
static int dice2;
public static void main(String[] args) {
//variables
int dice1;
int dice2;
int numWins = 0;
int numLosses = 0;
//Call the welcome method
welcome();
//fetch random numbers
/*
* **************************************************************
*welcome method
*welcome user
*no parameters
*no return
****************************************************************
*/
}
public static void welcome() {
System.out.println("Welcome to a Lucky (for me) Dice Game! \nFEELING LUCKY?!? Hope you brought lots of CASH!");{
}
int die1 = (int) (Math.random()*6 + 1);
int die2 = (int) (Math.random()*6 + 1);
int dice = die1 + die2;
System.out.println("Roll: total = " + dice);
int numWins = 0;
int numLosses = 0;
if (dice == 7 || dice == 11){
System.out.println("Woah!!! With a: "+dice+ " You WIN!!!!!!!!");
numWins++;
}
else if (dice == 2 || dice == 3 || dice == 12){
System.out.println("Sorry, with a "+dice+" You lose:(");
numLosses++;
}
while (dice != 0){
int die3 = (int) (Math.random()*6 + 1);
int die4 = (int) (Math.random()*6 + 1);
int dice2 = die3 + die4;
System.out.println("Roll: total = "+dice2);
if (dice2 == 2|| dice2 == 3 || dice2 == 12){
System.out.println("Sorry, with a "+dice2+" You lose:(");
numLosses++;
dice = 0;
}
else if (dice2 == 7 || dice2 == 11){
System.out.println("Woah!!! With a: "+dice2+ " You WIN!!!!!!!!");
numWins++;
dice = 0;
}
{
System.out.println("So far you have won " + numWins +
" times and lost " + numLosses + " times, ");
{
}
}
}
}}
這是我的輸出,當我運行它:
Welcome to a Lucky (for me) Dice Game!
FEELING LUCKY?!? Hope you brought lots of CASH!
Roll: total = 2
Sorry, with a 2 You lose:(
Roll: total = 8
So far you have won 0 times and lost 1 times,
Roll: total = 10
So far you have won 0 times and lost 1 times,
Roll: total = 8
So far you have won 0 times and lost 1 times,
Roll: total = 3
Sorry, with a 3 You lose:(
So far you have won 0 times and lost 2 times,
計數器應止贏後聲明或丟失。我該如何解決?
首先,你需要了解如何格式化,尤其是縮進代碼以及它是當編譯器並不重要,關鍵是我們的代碼的理解,現在你以後瞭解它的Java語言的一部分。編程語言的大部分結構都是爲了讓人們能夠理解它。所以請嘗試修復您的代碼。縮進所有塊4個空格,而不是隨機。同一塊上的所有代碼都應該縮進一樣。如果您認真對待您的問題,請認真溝通您的代碼。 – 2014-10-11 01:29:59
對不起 - 這是我第一次使用Java,所以我還在學習。 – user3587461 2014-10-11 01:32:07
這一切都可以,但請立即修復您的代碼。此外,連續不超過一個空白行。 – 2014-10-11 01:34:10