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)

5 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

  2. Long time reader, first time commenter — so, thought I’d drop a
    comment.. — and at the same time ask for a favor.

    Your wordpress site is very simplistic – hope you don’t mind me asking what
    theme you’re using? (and don’t mind if I steal it?
    :P)

    I just launched my small businesses site –also built in wordpress like yours– but the theme slows (!) the site down quite a bit.

    In case you have a minute, you can find it by searching for “royal cbd” on Google (would appreciate any feedback)

    Keep up the good work– and take care of yourself during the coronavirus scare!

    ~Justin

Leave a Reply

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