215k views
2 votes
Java: Programming Question: Reverse OrderWrite a program that reads ten integers into an array; define another array to save those ten numbers in the reverse order. Display the original array and new array. Then define two separate methods to compute the maximum number and minimum number of the array.Sample Run:Please enter 10 numbers: 1 3 5 8 2 -7 6 100 34 20The new array is: 20 34 100 6 -7 2 8 5 3 1The maximum is: 100The minimum is: -7Bonus: Determine how many numbers are above or equal to the average and how many numbers are below the average.

User Gdelab
by
5.8k points

1 Answer

2 votes

import java.util.Scanner;

import java.util.Arrays;

public class JavaApplication47 {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Please enter 10 numbers: ");

String [] nums = scan.nextLine().split(" ");

int newNums[] = new int [nums.length];

int w = 0, total = 0, above = 0, below = 0;

for (int i=(nums.length-1); i>=0;i--){

newNums[w] = Integer.parseInt(nums[i]);

w++;

}

System.out.println("The old array is: "+Arrays.toString(nums));

System.out.println("The new array is: "+Arrays.toString(newNums));

Arrays.sort(newNums);

System.out.println("The maximum is: "+newNums[9] + "\\The minimum is: "+newNums[0]);

for (int i : newNums ){

total += i;

}

total = total / 10;

for (int i : newNums){

if (i >= total){

above += 1;

}

else{

below += 1;

}

}

System.out.println("There are "+above+" numbers above or equal to the average.");

System.out.println("There are "+below+" numbers below the average.");

}

}

I hope this helps!

User IonicSolutions
by
4.5k points