Question: Java Programming Topic: Conditionals and Strings Program: The area of a hexagon can be computed using the following formula (s is the length of a

Java Programming

Topic: Conditionals and Strings

Program: The area of a hexagon can be computed using the following formula (s is the length of a side): 6 times s squared over 4 times the tan(pi/6)

I have created the following code below...

import java.util.Scanner; import java.text.DecimalFormat; public class AreaHexagon { public static void main(String[] args) { Scanner in = new Scanner(System.in); DecimalFormat twoDForm = new DecimalFormat("#.##"); System.out.print("Enter the side:"); double side = in.nextDouble(); double area = 6 * Math.pow(side, 2) / (4 * Math.tan(Math.PI / 6)); System.out.println("The area of the hexagon is " + twoDForm.format(area)); } }

But it gives me the following error message in MyProgrammingLab. It seems it wants to output with two decimal points, but my code is only outputting as one. How do I fix this?Java Programming Topic: Conditionals and Strings Program: The area of a hexagon

Problems Detected: The contents of your standard output is incorrect. Given the following was entered from the keyboard: 8.8 you displayed: instead of: Enter the side:The area of the hexagon is 201.20 Failed 1 out of 4 test runs. Failed Test Run The contents of your standard output is incorrect. Interactive Session - W Hide Invisibles Highlight: None Show Highlighted Only O Expected Result: Enter the side:8.84 The area.of.thehexagon.is.201.204 Your Code's Actual Result: Enter the side:8.84 The area.of.the.hexagon.is.201.24

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!