Member Avatar for krejar

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));
	}
}

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.

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

Member Avatar for hfx642

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!

Member Avatar for krejar

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));
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.