所以基本上我的问题出现在这个程序中,我会在将其放入
后更好地解释 package learning;
//This class has an important method that i have been working on called Dice6 don't delete
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class GameBoard {
public static void main(String[] args) {
System.out.println("Welcome To The Gameboard");
System.out.println("What is your name player 1?");
Scanner Scan = new Scanner(System.in);
String ScanResult1 = Scan.nextLine();
System.out.println("Well... " + ScanResult1 + " This is the Board");
System.out.println("~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~|");// Don't Question its
// placement its weird,
// but it works
System.out.println(" |");
System.out.println(" |~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~");
System.out.println("Lets start with a Dice Roll");
System.out.println(ScanResult1 + " Got a Roll of " + Dice6(10));
Scan.close();
}
static int Dice6(int y) {
ArrayList<Integer> Dice = new ArrayList<Integer>();
Dice.add(1);
Dice.add(2);
Dice.add(3);
Dice.add(4);
Dice.add(5);
Dice.add(6);
int DiceAmount = Dice.size();
while (DiceAmount != 6) {
DiceAmount= DiceAmount - 1;
Dice.add(Dice.size() + 1);
}
Collections.shuffle(Dice);
Collections.shuffle(Dice);
Integer DiceResult = Dice.get(3);
return DiceResult;
}
}
好的,我遇到的问题是来自 System.out.println(ScanResult1 +“滚了一下”+ Dice6(10)); 基本上我试图通过使用参数10 ....在ArrayList中添加数组值。假设发生的是假设在ArrayList中有10个值取决于我在参数中放入的内容....我已经尝试了很多东西,并做了很多修复,我曾做过(空白x:骰子)显示所有值,10只没有出现只有原来的6 ....如果任何机构都知道如何解决这个问题请告诉我
答案 0 :(得分:0)
这段代码毫无意义:
int DiceAmount = Dice.size(); /* this will be 6 */
while (DiceAmount != 6) { /* this will never be true, do you want y here? */
DiceAmount= DiceAmount - 1; /* huh? I think you want addition here */
Dice.add(Dice.size() + 1); /* this will never happen */
}
更多&#34;回答表格&#34; ...使用此:
int DiceAmount = Dice.size();
while (DiceAmount != y)
DiceAmount= DiceAmount + 1;
Dice.add(Dice.size() + 1);
}