Write a program that inputs 4 numbers and calculates the sum, average and product of all the numbers.

public static void main(String[] args) {

Scanner x=new Scanner(System.in);

int a,b,c,d,sum,pro;

float avg;

System.out.println(“Enter number”);

a=x.nextInt();

System.out.println(“Enter number”);

b=x.nextInt();

System.out.println(“Enter number”);

c=x.nextInt();

System.out.println(“Enter number”);

d=x.nextInt();

sum=a+b+c+d;

avg=(a+b+c+d)/4;

pro=a*b*c*d;

System.out.println(“Sum of number is =”+sum);

System.out.println(“Avrge of numbers is=”+avg);

System.out.println(“Product of number is =”+pro);

}

Output:

run:

Enter number

2

Enter number

5

Enter number

3

Enter number

6

Sum of number is =16

Avrge of numbers is=4.0

Product of number is =180

BUILD SUCCESSFUL (total time: 5 seconds)

3 Comments on “Write a program that inputs 4 numbers and calculates the sum, average and product of all the numbers.”

  1. It again gives false average result…
    If the sum of 4 numbers is like 17…
    It gives avg 4.0..and the actual result is 4.25

Leave a Reply

Your email address will not be published. Required fields are marked *