这是新的计算机科学专业,试图弄清楚一些东西。因此,我应该采用用户定义的D6数量并将卷数与用户定义的奖金(我认为我的教授秘密地是DnD粉丝...)加在一起得出总数。我遇到的唯一困难是我的程序仅添加了最后一卷和奖金。到目前为止,这是我的代码:
import java.util.Random;
import java.util.Scanner;
public class Dice
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Random roll = new Random();
int rollValue = 0;
int numDice = 0;
int statBonus = 0;
int totalRoll = 0;
System.out.println("How many 6-sided die would you like to roll? ");
numDice = scan.nextInt();
System.out.println("What number would you like to add to the rolls? ");
statBonus = scan.nextInt();
scan.close();
for (int i = 0; i < numDice; i++)
{
rollValue = roll.nextInt(6) + 1;
System.out.println("Roll is: " + rollValue);
}
totalRoll = statBonus + rollValue;
System.out.println("The result of rolling " + numDice + " D6, and adding " + statBonus + " is: "
+ totalRoll);
}
}
如果有人可以指出正确的方向,那将是巨大的帮助!提前致谢!
-本
最佳答案
重写本节:
for (int i = 0; i < numDice; i++)
{
rollValue = roll.nextInt(6) + 1;
System.out.println("Roll is: " + rollValue);
}
totalRoll = statBonus + rollValue;
至
for (int i = 0; i < numDice; i++)
{
rollValue = roll.nextInt(6) + 1;
System.out.println("Roll is: " + rollValue);
totalRoll += rollValue;
}
totalRoll = statBonus + totalRoll;
换句话说,保持连续运行。