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
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();
  }
}
Comments
Leave a comment