0% found this document useful (0 votes)
0 views

Average number.java

The document contains a Java program that defines a class named 'Average' which includes a method to calculate and print the average of three user-input numbers. The program prompts the user to enter three integers, calculates their average, and displays the result. It also includes necessary imports and a main method to execute the program logic.

Uploaded by

Dillibabu G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Average number.java

The document contains a Java program that defines a class named 'Average' which includes a method to calculate and print the average of three user-input numbers. The program prompts the user to enter three integers, calculates their average, and displays the result. It also includes necessary imports and a main method to execute the program logic.

Uploaded by

Dillibabu G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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();

You might also like