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

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 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 Java program that takes in a string and a number and prints back the...
Write a Java program that takes in a string and a number and prints back the string from the number repeatedly until the first character... for example Pasadena and 4 will print PasaPasPaP. Ask the user for the string and a number Print back the string from the number repeatedly until the first character For both programs please utilize: methods arrays loops Turn in screenshots
use java for : 1. Write a method called indexOfMax that takes an array of integers...
use java for : 1. Write a method called indexOfMax that takes an array of integers and returns the index of the largest element. 2. The Sieve of Eratosthenes is “a simple, ancient algorithm for finding all prime numbers up to any given limit” (https://en.wikipedia. org/wiki/Sieve_of_Eratosthenes).Write a method called sieve that takes an integer parameter, n, and returns a boolean array that indicates, for each number from 0 to n -1, whether the number is prime.
Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point numbers.
Programing in Scala language: Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point numbers. Write separate methods to get an element (given parametersrow and col), set an element (given parametersrow, col, and value), and output the matrix to the console formatted properly in rows and columns. Next, provide an immutable method to perform array addition given two same-sized array.
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
Use if statements to write a Java program that inputs a single letter and prints out...
Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way: 2 = ABC    3 = DEF   4 = GHI    5 = JKL 6 = MNO   7 = PRS   8 = TUV 9 = WXY No digit corresponds to either Q or Z. For these 2 letters your program should print a message indicating that they are not...
with java code write The method prints a meaningful title with your name as the author....
with java code write The method prints a meaningful title with your name as the author. The method then generates THREE random numbers 0 - 4 and reports how many of the numbers are the same. 2-Use a loop to repeat 10 times. the output should be like this Title title title by Your Name 4, 3, 4 two are the same 4, 0, 0 two are the same . . . 2, 0, 4 none are the same 4,...
Write code that takes the size of their foot from user and prints out suggested sandal...
Write code that takes the size of their foot from user and prints out suggested sandal size. Shoe Range Sandal Size <= 5 (inclusive) Small 5 ~ 9 (inclusive) Medium 9 ~ 12 (inclusive) Large above 12 X-Large example: Please enter your shoe size: (user types 6.5) Your sandal size is Medium.
in Java, write a program that takes an input of 4 numbers and splits them into...
in Java, write a program that takes an input of 4 numbers and splits them into 4 separate lines. EXAMPLE: so if input is 1994 the output should be 1 9 9 4
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT