Write a Java program that asks the user to input a positive
Solution
package pkg;
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
public class ReadFileExample1
{
public static void main(String[] args)
{
int[] numbers;
int sum = 0, n;
double avg;
//Read the data from user(command)
Scanner sc = new Scanner(System.in);
System.out.println(\"Enter the size of an array\");
n = sc.nextInt();
numbers = new int[n];
//List<Integer> ints = new ArrayList<Integer>();
Random r = new Random();
int Low = 5;
int High = 555;
//Generates 10 Random Numbers in the range 1 -20
for(int i = 0; i < n; i++) {
//Read the random value between 5 to 555
int Result = r.nextInt(High-Low) + Low;
//store in an array
numbers[i] = Result;
//calcuate the sum
sum += Result;
}//end for loop
//calcuate the average
avg = sum / n;
System.out.println(\"Numbers Generated: \" + Arrays.toString(numbers));
System.out.println(\"Sum: \" + sum);
System.out.println(\"Average: \" + avg);
} // end main
} // end class
