![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [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; |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |