Problem: Get Average
Create a
method that finds the average of three numbers. Read in internet about java
methods. Check the naming conventions. Invoke your method and test it. Format
the output to two digits after the decimal separator. The placeholder is %.2f
import java.util.Scanner; public class GetAverage { public static void main(String[] args) { Scanner console = new Scanner(System.in); double a = Double.parseDouble(console.nextLine()); double b = Double.parseDouble(console.nextLine()); double c = Double.parseDouble(console.nextLine()); double averageOfNums = GetAverage(a, b, c); System.out.println(String.format("%.2f", averageOfNums)); } private static double GetAverage(double a, double b, double c) { double averageOfNums = (a + b + c)/3.0; return averageOfNums; } }
No comments:
Post a Comment