Trying to make an array of random numbers. Here is what I have so far:
public static void main(String[] args) {
randomArray(5);
}
public static int randomInt(int low, int high){
int x=0;
for (int i=0;i<10;i++){
x= (int)(Math.random ()*high)+low;
System.out.print(x);
}
return x;
}
public static int[] randomArray(int n){
int[] a = new int [n];
for (int i = 0;i<a.length;i++){
a[i]=randomInt (0,100);}
printArray(a);
return a;
}
public static void printArray (int[]a) {
for (int i = 0; i<a.length;i++){
System.out.println(a[i]);
}
}
}
this returns something along the lines of
9265956792478464547638861753937389642303686408882492318499964845942725987325868511898811389
42
49
73
72
Which is way, way out of range. Any ideas?
Because you have a: System.out.print(x)
inside randomInt
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments