118k views
1 vote
Write a java program to add three numbers and find their total and average. Submit the source code. Display the numbers and their average in the following format

a) First Number =
b) Second Number =
c) Total =
d) Average =

User TheAJ
by
8.8k points

1 Answer

5 votes

Final answer:

This detailed answer provides a Java program that adds three numbers and finds their total and average. It also includes formatted output to display the numbers and their average in a specific format.

Step-by-step explanation:

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.print("Enter the first number: ");
int num1 = sc.nextInt();

System.out.print("Enter the second number: ");
int num2 = sc.nextInt();

System.out.print("Enter the third number: ");
int num3 = sc.nextInt();

int total = num1 + num2 + num3;
double average = total / 3.0;

System.out.println("First Number = " + num1);
System.out.println("Second Number = " + num2);
System.out.println("Third Number = " + num3);
System.out.println("Total = " + total);
System.out.println("Average = " + average);
}

}

User Maerlyn
by
7.8k points