I am supposed to create an array of 1000 ints and write a method to find the largest int and then print it. This is what I have so far:
public static int findLargest(int[] numbers){
int largest = numbers[0];
for(int i = 1; i < numbers.length; i++){
if(numbers[i] > largest){
largest = numbers[i];
}
}
return largest;
}
First, how do I create an array with 1000 randomly generated ints? I tried int[] array = new (int)(Math.random()); but I don't know how to get it to do 1000 random numbers. Second, how do I print the result? Thanks in advance for any help.