Java Programming Tutorial 30 Question

0 Onur Cevik · January 20, 2015
Hey guys newbie here,

Sorry if I violated any kind of forum rule.

Here is the link for the tutorial: http://www.youtube.com/watch?v=pHxtKDENDdE&list=PLADA5053D207C95C6&index=30

The question is:

I don't get why the Frequency output is always in hundreds. I feel like the output should be anything in between 1-1000, but it only outputs numbers like 1**. Hope I made myself clear. Would appreciate any help.

Here is the code if you don't want to check the tutorial:

public class ders {
public static void main(String[] args) {

Random rand = new Random();
int freq[] = new int[7];

for(int roll=1; roll<=1000; roll++){

++freq[1+rand.nextInt(6)];
}

System.out.println("Face\tFrequency");

for(int face=1; face<freq.length; face++){

System.out.println(face + "\t" + freq[face]);
}
}
}

Post a Reply

Replies

Oldest  Newest  Rating
+2 Tim Herreijgers · January 21, 2015
You have the same chance to get a 1 as to get a 2 and the same chance to get a 2 as to get a 3 etc.  This means that you should get close to the same amount of 6 as the amount of 1 etc.  It is totally normal that those numbers are really close together. If you divide 1000 by 6 you get 166. So all number should be close to 166.

I hope this answers your question.
0 Onur Cevik · January 29, 2015
Thanks :)
  • 1

Java / Android Development

107,070 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator