Prachi want to make an algorithm to input four number some up calculate average and print the sum and average but before writing an algorithm she want to make a flock cart for that so draw a floor cart to input four number sum up calculate average and print sum and average
Answers
Answered by
0
Answer:
import java.util.Scanner;
public class average
{
public static void main(String []args)
{
Scanner sc = new Scanner(System.in);
float num1, num2, num3, num4, sum;
float avg;
System.out.println("Enter the four numbers seperately");
num1 = sc.nextInt();
num2 = sc.nextInt();
num3 = sc.nextInt();
num4 = sc.nextInt();
sum = num1+ num2+ num3+ num4;
avg = sum/4;
System.out.println("The sum of the four numbers is "+sum);
System.out.println("The average of the numbers are "+avg);
}
}
Explanation:
You have to use float or else it won't give the correct answer in decimals
Similar questions
Computer Science,
3 months ago
English,
3 months ago
Math,
3 months ago
Math,
6 months ago
Geography,
11 months ago