Answer to Question #326369 in Java | JSP | JSF for Isaac

Question #326369

Write a program that does the following:


a. Prompts the user to input five decimal numbers.

b. Prints the five decimal numbers.

c. Converts each decimal number to the nearest integer.

d. Adds the five integers.

e. Print the sum and the average of the five integers


1
Expert's answer
2022-04-09T17:52:14-0400
import java.util.Scanner;
class App {
    public static void main(String[] args) {
        Scanner keyBoard = new Scanner(System.in);
        double[] numbers=new double[5];
        int[] numbersInt=new int[5];
        System.out.println("Input five decimal numbers: ");
		for(int i=0;i<5;i++){
		    numbers[i]=keyBoard.nextDouble();
		}
		double sum=0;
		for(int i=0;i<5;i++){
		    System.out.print(numbers[i]+" ");
		    numbersInt[i]=(int)Math.round(numbers[i]);
		    sum+=numbersInt[i];
		}
		System.out.print("\nDecimal number to the nearest integer.\n");
		for(int i=0;i<5;i++){
		    System.out.print(numbersInt[i]+" ");
		}
		double average=sum/5.0;
		System.out.print("\nThe sum of the five integers: "+sum);
		System.out.print("\nThe average of the five integers: "+average);
		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