I'm trying to print a histogram, but am having trouble piecing it all together in main. I'm new to arrays, so if anyone can help with this, it'd be much appreciated. Here are my methods:
public static void main(String[] args) {
randomIntArray(5);
}
public static int randomInt(int low, int high){
int x= (int)(Math.random ()*high)+low;
return x;
}
public static int[] randomIntArray(int n){
int[] a = new int [n];
for (int i = 0;i<a.length;i++){
a[i]=randomInt (0,100);
}
System.out.println(printHist(a));
return a;
}
public static int[] printHist(int[]a){
int[] k = new int[11];
int i=0;
while (i<=10) {
int counter = 0;
int h=0;
while(h<a.length) {
if (a[h] == i) {
counter++;
h++;
}
h++;
}
k[i] = counter;
i++;
}
return k;
}
And here's what I get as output.
[I@fb53f6
Do I need to rethink the way I'm doing this, or is there a simple fix?