gpt4 book ai didi

Java:需要添加用户自定义的骰子数

转载 作者:行者123 更新时间:2023-11-30 08:39:18 25 4
gpt4 key购买 nike

这里是新的计算机科学专业,正在尝试弄清楚一些事情。所以,我应该采用用户定义的 D6 数量并将卷数加在一起,以及用户定义的奖金(我认为我的教授 secret 地是 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;

换句话说,保持总计。

关于Java:需要添加用户自定义的骰子数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36213458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com