lundi 29 mars 2021

Need help to create an array of randomly generated numbers within a range and then displaying the frequency of each number in that range

As the title implies I'm having trouble writing a code that can do as asked. What I have is:

public static void main(String[] args) {
       int[] runs = new int[24];  
       for(int i = 0; i < runs.length; i++) {
          runs[i] = (int)(Math.random()*3 + 1);
          int count = 1;
          for (int j = i+1; j<i;j++) {
              if (runs[i] == runs[j]) {
                  count++;
              }
          }
          System.out.println(runs[i] + " " + count);          
        }   
   }

However, whenever I run my program, it will just list the randomly generated numbers and then a 1 next to them. Any help is appreciated, thank you!




Aucun commentaire:

Enregistrer un commentaire