Computer Science, asked by osama2749, 6 months ago

write a program in java to input any 4 number. calculate and display the sum. average and product of the 4 numbers​

Answers

Answered by vijayghore
2

Answer:

import java.util.*;

class Sample

{

   public static void main(String args[])

   {

         int n1, n2, n3, n4, sum, product;

         double average;

         System.out.println("Enter four numbers");

         Scanner s = new Scanner(System.in);

         n1 = s.nextInt();

         n2 = s.nextInt();

         n3 = s.nextInt();

         n4 = s.nextInt();

         s.close();

         sum = n1 + n2 + n3 + n4;

         average = sum / 4.0;

         product = n1 * n2 * n3 * n4;

        System.out.println("Sum = "+sum+"\nAverage = "+average+"\nProduct = "+product);

   }

}

Answered by anindyaadhikari13
5

Question:-

Write a program to input 4 numbers and calculate and display the sum, product and average of 4 numbers.

Program:-

import java.util.*;

class Numbers

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter 4 numbers.");

double a, s=0,av, p=1;

for(int i=1;i<=4;i++)

{

a=sc.nextInt();

s+=a;

p*=a;

}

av=s/4.0;

System.out.println("Sum is: "+s);

System.out.println("Average is: "+av);

System.out.println("Product is: "+p);

}

}

Similar questions