在我的程序中,应该创建13个数组,以保持范围2-12的总和,在这种情况下,将滚动两个模具卷1000时间,并且应该打印出死亡加入的卷数“2”。然而,最初该程序工作,但后来意识到我需要在程序中使用数组,而不是仅使用一个math.random方法。我已经尝试过,只是在main方法中打印数组值,除了进行更多的错误。此外,我研究了使用直方图来调用数组,除了我以前的尝试,它创造了严重的更多的错误类型不匹配不能从布尔转换为Int(自定义方法中的数组)
我的问题是;
1:我将如何解决的主要误差,允许它从布尔转换为int
2:如何做一个return语句的工作,它必须为数组不同的比一般的整数
任何指导或信息将不胜感激。
import java.io.*;
public class dont {
public static void main(String[] args) throws Exception {
// System.out.println(input());
int[] counts = new int[13];
System.out.print("The number of times it rolls 4 on two 6 sided dice :" + counts);
}
public static int input() throws IOException {
BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Hello and welcome to the program");
System.out.println("In this program two six sided dices will be rolled and one eleven sided dice will be rolled (1000 times each");
int sum;
int[] counts = new int[13];
System.out.println("The dices will be rolled to determine the odds of how many times the roll 2 comes up on both dies(Press any key to con't) ");
myInput.readLine();
//int count2=0;
int Sixside;
for (int i = 0; i < 1000; i++)
{
// two dice that add to 4, after being rolled one thousand times
Sixside = (int)(Math.random()*6+1)+(int)(Math.random()*6+1) == 4;
//print the number of times they add to 4
counts[sum]++;
}
counts[i] = Sixside;
{
//return array to main
return counts [13];
}
}
}
在行int [] counts = input();我得到错误不兼容的类型 – user2184171 2013-03-20 14:42:18
@ user2184171糟糕。我忘了更改方法声明。编辑。 – raptortech97 2013-03-20 15:09:10
如果我添加了一个11面的骰子,我会粘贴除了(int)(Math.random()* 11 + 1)以外的其他东西,然后用一个11面骰子计算它滚动的次数2吗? – user2184171 2013-03-20 15:43:16