Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Question About Checking Values of Arrays

$
0
0
So for the project I am working on I have an array that randomly generates 25 integers between the values of -10 and 15. I have a value stored to each element of the array but now I need to print out how many times each number is generated. The code I have so far is as follows.
  public static void main(String[] args) {
    randomArray();
  }

  public static void randomArray() {
    int[] intArray = new int[25];
    for(int I = 0; I < intArray.length - 1; I++) {
      intArray[I] = ((int)Math.random() * 25) -10;
      // ignore the math.random above, that's not how I actually did it
      // that is just for example, my actual method works properly
    }
  }

Now I just need to get the values of each element in intArray and print how many times each value occurs. Any ideas as to how are greatly appreciated. Thanks!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>