Instructions
Input
The first line contains the size of the array/list.
The next lines contains an integer on each.
5
5
34
3
23
10
Output
A line containing an integer.
34
package random;
import java.util.Random;
import java.util.Scanner;
public class RandomArray {
public static void main(String[] args) {
Random rand = new Random();
Scanner scan = new Scanner(System.in);
System.out.println("Enter the size of the array\n");
int n = scan.nextInt();
int [] arr = new int[n];
for(int i=0; i<n; i++){
int x= rand.nextInt(50);
arr[i] = x;
}
int max = arr[0];
for(int i=0; i<n; i++){
if(arr[i]>max){
max = arr[i];
}
}
System.out.println("The largest is: "+max);
}
}
Comments
Leave a comment