[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

array question

I am trying to put out array elements as counters but one line highlights as a mistake and dont know where the mistake lies :)
Thanks for all the help:

The line that is causing problems is the ++freq[1 + rand.nextInt(6)];


import java.util.Random;
public class demo {
    public static void main(String[] args) {
        Random dice = new Random ();

        int freq[] = new int [7];

        for (int roll = 1;roll < 1000; roll++){
            ++freq[rand.nextInt(6)];
        }
        System.out.println("Face\tFrequency");
        
        for(int face = 1; face < freq.length; face++){
            System.out.println(face + "\t" + freq[face]);
        }
}
}

Open in new window

0
Anda09
Asked:
Anda09
1 Solution
 
ozlevanonCommented:
Your Random instance is called "dice" and not "rand". Try changing the line to

            ++freq[dice.nextInt(6)];
0
 
Anda09Author Commented:
worked like a charkm thank you.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now