View Single Post
  #1 (permalink)  
Old 06-10-2007, 05:18 PM
Shivers20
Posts: n/a
[SOLVED] java program using method call for a cylinder.Is this correct?

Write a general-purpose method that uses 2 double parameters corresponding to the cylinder's radius& height & returns the cylinders volume.
Make sure your method is called from main() &correctly returns a value to main(). Have main() display the value returned & test the method by passing various data to it & verifying the returned value.

[code]
import java.util.Scanner;
import java.text.*;

public class cylinderVolume
{
public static void main(String [] args)
{
Scanner input= new Scanner(System.in);
double radius, height, pi =3.14, volume;
System.out.print("Please enter a radius:");
radius= input.nextDouble();
System.out.print("Please enter a height:");
height= input.nextDouble();
volume= computeVolume(radius,height);
System.out.println("The total volume is " + volume);
}
public static double computeVolume(double radius, double height)
double v;
v= Math.pow(radius,2) * height * 3.14;
return v;

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!