Q.
3 Print the average of three numbers entered by user by creating a class named 'Average' having a
method to calculate and print the average.
import java.util.Scanner;
class Average {
// Method to calculate and print the average
void calculateAverage(int num1, int num2, int num3) {
int sum = num1 + num2 + num3;
double average = sum / 5.0; // Calculate the average
System.out.println("The average is: " + average);
// Main method
public static void main(String[] args) {
// Create a Scanner object to take input from the user
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter three numbers
System.out.println("Enter the first number:");
int num1 = scanner.nextInt();
System.out.println("Enter the second number:");
int num2 = scanner.nextInt();
System.out.println("Enter the third number:");
int num3 = scanner.nextInt();
// Create an object of the Average class
Average averageCalculator = new Average();
// Call the calculateAverage method
averageCalculator.calculateAverage(num1, num2, num3);
// Close the scanner
scanner.close();