Saturday, 3 September 2011

Array Elements as counter in java


import java.util.Random;
class apples
{
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("Index\tFrequency");
for(int face=0;face<=6;face++)
System.out.println(face+"\t"+freq[face]);
}
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.