Answer to Question #311935 in Java | JSP | JSF for Joy

Question #311935

Create a program that will enter at least five numbers, compute the average, and print the said numbers in reverse order.


Sample output:


Enter the number of elements: 5


enter the value of item number 1: 80

enter the value of item number 2: 82

enter the value of item number 3: 84

enter the value of item number 4: 82

enter the value of item number 5: 85


The average of 5 element is 82.60


Reverse order of 5 elements: 85, 82, 84, 82, 80



1
Expert's answer
2022-03-15T07:12:24-0400


import java.util.Scanner;


public class App {


	/** Main Method */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in); // Create a Scanner
		System.out.print("Enter the number of elements: ");
		int size = keyBoard.nextInt();
		double numbers[] = new double[size];
		double sum = 0;
		for (int i = 0; i < size; i++) {
			System.out.print("enter the value of item number " + (i + 1) + ": ");
			numbers[i] = keyBoard.nextDouble();
			sum += numbers[i];
		}
		double average = sum / (double) size;
		System.out.printf("The average of " + size + " element is %.2f", average);
		System.out.print("\nReverse order of " + size + " elements: ");
		for (int i = size - 1; i > 0; i--) {
			System.out.print(numbers[i] + ",");
		}
		System.out.print(numbers[0]);
		keyBoard.close();
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS