在我的程序中,应该创建 13 个数组,以保存范围 2-12 的总和,在这种情况下,两个骰子滚动了 1000 次,并且应该打印出骰子添加到滚动的次数“2 ”。但是,最初该程序可以工作,但后来意识到我需要在程序中使用数组,而不仅仅是使用单个 math.random 方法。我已经尝试过,在 main 方法中简单地打印数组值,但出现更多错误。此外,我研究了使用直方图调用主数组的方法,除了我之前的尝试,它产生了更多的错误
我的问题是;
1:我将如何修复主要错误,允许它从 Boolean 转换为 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];
}
}
}