Using import java.util.Random, create a simple java code that populates an array with 10 random numbers (choosing between a range of 20 to 90) and then outputs the largest number.
ANSWER: Here I am giving you the code and output please like it.
CODE:
import java.util.Random;
public class Main
{
public static int getRandomNumberUsingNextInt(int min, int max)
{
Random random = new Random();
return random.nextInt(max - min) + min;
}
public static void main(String[] args) {
int arr[]= new int[10];
for(int i=0;i<10;i++){
arr[i]=getRandomNumberUsingNextInt(21,91);
}
int max=arr[0];
System.out.println("Your array :");
for(int i=0;i<10;i++){
if(arr[i]>max)
max=arr[i];
System.out.print(arr[i]+" ");
}
System.out.println("\nLargest
number:"+max);
}
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.