Question

In: Computer Science

Write a Java method called printAvg that takes in two floating point numbers and prints out...

Write a Java method called printAvg that takes in two floating point numbers and prints out the average of them.

Solutions

Expert Solution

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:


Related Solutions

in Java Write a method called randomNumber that returns a random floating-point number in the range...
in Java Write a method called randomNumber that returns a random floating-point number in the range of [-20.0, 50.0). (hints: use Random class in the method)
In Java Write a method called findMax that accepts three floating-point number as parameters and returns...
In Java Write a method called findMax that accepts three floating-point number as parameters and returns the largest one.(hints: use conditional statement in the method)
FOR JAVA Write a method called findNum that takes a two-dimension array of integers and an...
FOR JAVA Write a method called findNum that takes a two-dimension array of integers and an int as parameters and returns the number of times the integer parameter appears in the array. For example, if the array (as created by the program below) is 10 45 3 8 2 42 3 21 44 And the integer parameter is 3, the value returned would be 2 (the number 3 appears two times in the array) public class HomeworkA { public static...
in java language Write a method called findNums that takes a two-dimension array of integers and...
in java language Write a method called findNums that takes a two-dimension array of integers and an int as parameters and returns the number of times the integer parameter appears in the array. For example, if the array (as created by the program below) is 10 45 3 8 2 42 3 21 44 And the integer parameter is 3, the value returned would be 2 (the number 3 appears two times in the array) public class Question2 {   ...
Java programming. Write a public Java class called DecimalTimer with public method displayTimer, that prints a...
Java programming. Write a public Java class called DecimalTimer with public method displayTimer, that prints a counter and then increments the number of seconds. The counter will start at 00:00 and each time the number of seconds reaches 60, minutes will be incremented. You will not need to implement hours or a sleep function, but if minutes or seconds is less than 10, make sure a leading zero is put to the left of the number. For example, 60 seconds:...
Java Write a valid Java method called printReverse that takes a String as a parameter and...
Java Write a valid Java method called printReverse that takes a String as a parameter and prints out the reverse of the String. Your method should not return anything. Make sure you use the appropriate return type.
Java Write a method that reads a text file and prints out the number of words...
Java Write a method that reads a text file and prints out the number of words at the end of each line
Write a recursive method that takes a String argument and recursively prints out each word in...
Write a recursive method that takes a String argument and recursively prints out each word in the String on a different line. Note: You will need to use methods such as indexOf() and substring() within the String class to identify each word and the remaining string. For example, if the input was “the cat purred”, then the method would print the following to the Java console: the cat purred Challenge Problem Write a recursive method that takes a string as...
Write a public Java class called DecimalTimer with public method displayTimer, that prints a counter and...
Write a public Java class called DecimalTimer with public method displayTimer, that prints a counter and then increments the number of seconds. The counter will start at 00:00 and each time the number of seconds reaches 60, minutes will be incremented. You will not need to implement hours or a sleep function, but if minutes or seconds is less than 10, make sure a leading zero is put to the left of the number. For example, 60 seconds: 00:00   00:01...
in java Write an application that gets two numbers from the user and prints the sum,...
in java Write an application that gets two numbers from the user and prints the sum, product, difference and quotient of the two numbers in a GUI.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT