Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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?image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions