Good afternoon! i am working on an assignment an having a bear of a time with one of the requirements. I am to establish formatting of the console output to 2 places after the decimal, but my current code is only showing a single. Any help would be greatly appreciated!!
import java.util.Scanner; public class Chpt6_Project { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the length: "); double length = input.nextDouble(); System.out.print("Enter the width: "); double width = input.nextDouble(); System.out.print("Enter the height: "); double height = input.nextDouble(); double area = calcArea(length, width, height); System.out.printf("The surface area for a rectangular prism "+ length + " inches long, " + width + " " + "inches wide, and " + height + " inches tall is " + area + " square inches. "); } public static double calcArea(double num1, double num2, double num3) { double area = ((num1 * num2) + (num1 * num2) + (num1 * num3) + (num1 * num3) + (num2 * num3) + (num2 * num3)); return area; } }
console is showing:
Enter the length: 4
Enter the width: 2
Enter the height: 1
The surface area for a rectangular prism 4.0 inches long, 2.0 inches wide, and 1.0 inches tall is 28.0 square inches.