the space below, write a program to calculate the product and average of 4 numbers using INPUT
statements and print the product and average.
Share
the space below, write a program to calculate the product and average of 4 numbers using INPUT
statements and print the product and average.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int []a=new int[4];
int b;
int product=1;
double ave=0;
double average;
System.out.println("Enter 4 numbers ");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
}
for(int j=0;j<a.length;j++)
{
b=a[j];
product=product*b;
ave=ave+a[j];
}
average=ave/4;
System.out.println("Product= "+product+" and average= "+average);
}
}
Explanation: