In: Computer Science
Write a Java method called printAvg that takes in two floating point numbers and prints out the average of them.
Complete Java program to the given requirement:
import java.util.Scanner;
public class ComputeAverage {
public static void main(String[] args) {
//Scanner class object to read
input from keyboard/user
Scanner scan = new
Scanner(System.in);
//ask the user to enter two
floating point numbers
System.out.print("Enter number
one:");
float numOne = (float)
scan.nextDouble();
System.out.print("Enter number
one:");
float numTwo = (float)
scan.nextDouble();
//calling printAvg() method
printAvg(numOne,numTwo);
}
//method that takes in two floating point numbers and
prints out the average of them.
public static void printAvg(float numOne, float
numTwo) {
System.out.print("Average of
"+numOne+" and "+numTwo+" is:"+(numOne+numTwo)/2);
}
}
Output: