Answer:
The program to this question as follows:
Program:
import java.util.*; //import package
class Average //defining class Average
{
public static void main(String[] args) //defining main method
{
int a1,b2,c3;//defining integer variable
float avg; //defining float variable
Scanner obz=new Scanner(System.in); //creating scanner class object
System.out.print("input first number: "); //print message
a1=obz.nextInt(); //input value by user
System.out.print("input second number: "); //print message
b2=obz.nextInt(); //input value by user
System.out.print("input third number: "); //print message
c3=obz.nextInt(); //input value by user
avg=a1+b2+c3/3; //calculating average
System.out.print("The average of "+a1+","+b2+",and "+ c3+"="+ avg);//print value
}
}
Output:
input first number: 8
input second number: 10
input third number: 18
The average of 8,10,and 18=24.0
Explanation:
In the above code, a class "Average" is defined inside this class the main function is declared in this method three integer variable "a1, b2, and a3" is declared, which input the value from the user side. in this method, a float variable avg is defined that calculates its average value.
- In the next step, a scanner class object is created, that uses the above integer variable values.
- In the "avg" variable add all integer variables then divide its value by 3. At the print, method is used that prints avg variable value.