0

I think my issue is in line 18. The program runs just fine, but my answer isn't correct when I enter a radius and height. Not sure what I am doing wrong here.

import java.util.Scanner;
import java.text.DecimalFormat;

public class ConeA
{
   public static void main (String[] args)
	{
	   double surface;
		
	   Scanner scan = new Scanner (System.in);
		
		System.out.print ("Enter the radius: ");
		double radius = scan.nextDouble();
		
		System.out.print("Enter the height: ");
		double height = scan.nextDouble();
		
		surface = Math.PI * radius * Math.pow(radius, 2) + Math.pow(height, 2);
		
		DecimalFormat fmt = new DecimalFormat ("0.##");
		
		System.out.println("The surface area of the cone is: " +
		   fmt.format(surface));
	}
}
5
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by krejar
0

my answer isn't correct

Please copy and paste here the input and output from the program and explain what is wrong with the output and show what the output should be.

Is your problem:
you don't have the correct equation
or your code is not following the equation that you have.

0

Make sure to use parentheses in the equation to follow the right sequence of operations

Edited by zeroliken: n/a

-1

The surface area of a cone is made up of two parts, added together.
1. The surface area of the base = Pi * R^2
2. The Lateral surface area = (Perimiter of Base * Slant Height [NOT Cone Height]) / 2

Perimiter = 2 * PI * R;
Slant Height = root (R^2 * CH^2);

Assembly Required!

Edited by hfx642: n/a

0

I fixed it. I was missing Math.sqrt

import java.util.Scanner;
import java.text.DecimalFormat;

public class ConeA
{
   public static void main (String[] args)
	{
	   double surface;
		
	   Scanner scan = new Scanner (System.in);
		
		System.out.print ("Enter the radius: ");
		double radius = scan.nextDouble();
		
		System.out.print("Enter the height: ");
		double height = scan.nextDouble();
		
		surface = Math.PI * radius * Math.sqrt(Math.pow(radius, 2) + Math.pow(height, 2));
		
		DecimalFormat fmt = new DecimalFormat ("0.##");
		
		System.out.println("The surface area of the cone is: " +
		   fmt.format(surface));
	}
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.