- import java.util.*;
- import java.lang.*;
- import java.io.*;
- import.java.text.*;
- import java.text.DecimalFormat;
- public class ConeArea {
- /**
- * The radius of the cone.
- */
- static double radius;
- /**
- * The radius of the cone.
- */
- static double height;
- /**
- * The radius of the cone.
- */
- static double theVolume;
- /**
- * Calculates the volume of a cone.
- * @return double representing volume of cone
- * @param radius
- * @param height
- */
- static public double volume(double radius, double height)
- {
- // Note: volume = 1/3 PI R^2 x height
- return Math.PI * Math.pow(radius, 2) * height / 3.0;
- }
- public static void main(String[] args) {
- DecimalFormat df = new DecimalFormat("0.00");
- java.util.Scanner s = new java.util.Scanner(System.in);
- System.out.print("Enter the radius of the cone > ");
- radius = s.nextDouble();
- System.out.print("Enter the height of the cone > ");
- height = s.nextDouble();
- theVolume = volume(radius, height);
- System.out.println("The volume of a cone with " +
- "radius " + df.format(radius) +
- " and height " + df.format(height) +
- " is " + df.format(theVolume));
- }
- }
Raw Paste