Develop a program which allows the user to enter numbers int

Develop a program which allows the user to enter numbers into an array. Input will be as follows: The user will enter the total number of integers to be entered into the array. The user will then enter that number of unique integers (negative or positive). Do not allow the number of values entered to exceed the array size. Develop methods to: \'main\' method Print the array Sort the array (YOU MUST DEVELOP YOUR OWN SORT METHOD - don\'t use someone else\'s) Determine the highest value Determine the lowest value Calculate the average value (double) Program Logic (algorithm): - Prompt and get the size of the array - Create the array of that size - Loop through the initialization of the array o Prompt the user for each value - Print the array - Sort the array - Print the array again - Output the highest value - Output the lowest value - Output the average

Solution


package arrayoperations;

import java.util.Scanner;

public class ArrayOperations {
  
public void min(int arr[]){
int i,min=arr[0];
for(i=0;i<arr.length;i++){
if(arr[i] < min){
min = arr[i];
}
}
System.out.println(min);
}
public void max(int arr[]){
int i,max=arr[0];
for(i=0;i<arr.length;i++){
if(arr[i] > max){
max = arr[i];
}
}
System.out.println(max);
}
public void avg(int arr[]){
int i,sum =0;
for(i=0;i<arr.length;i++){
sum = sum + arr[i];
}
System.out.println(sum);
}
public static void main(String[] args) {
int size;
int arr[],i;
ArrayOperations a = new ArrayOperations();
Scanner sc = new Scanner(System.in);
System.out.print(\"Enter the array size:\");
size = sc.nextInt();
arr= new int[size];
System.out.println(\"Enter array elements\");
for(i=0;i<size;i++){
arr[i] = sc.nextInt();
}
System.out.println(\"Array before sort\");
for(i=0;i<size;i++){
System.out.print(arr[i]+\"\\t\");
}
for(i=0;i<size;i++){
for(int j=0;j<size;j++){
if(arr[i] <= arr[j]){
int temp=arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
System.out.println(\"\ Array after sort\");
for(i=0;i<size;i++){
System.out.print(arr[i]+\"\\t\");
}
System.out.println(\"\ minimum value :\");
a.min(arr);
System.out.println(\"\ maximum value :\");
a.max(arr);
System.out.println(\"\ average value :\");
a.avg(arr);
}
  
}

Output:


Enter the array size:5
Enter array elements
9
10
5
8
6
Array before sort
9   10   5   8   6  
Array after sort
5   6   8   9   10  
minimum value :
5

maximum value :
10

average value :
38
BUILD SUCCESSFUL (total time: 9 seconds)

 Develop a program which allows the user to enter numbers into an array. Input will be as follows: The user will enter the total number of integers to be entere
 Develop a program which allows the user to enter numbers into an array. Input will be as follows: The user will enter the total number of integers to be entere

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site