1. (Computing the volume of a cylinder) Write a program that reads in the radius and length of a cylinder and computes volume using the following formulas:-
area = radius x radius x PI
volume = area x length
PI=3.14159
import java.util.Scanner;
/**
* @(#)Welcome.java
*
* Welcome application
*
* @author
* @version 1.00 2012/9/25
*/
public class Welcome {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a num for radius");
double radius = input.nextDouble();
System.out.println("Enter a num for length");
double length = input.nextDouble();
double area,volume;
area = radius * radius * 3.14159;
volume = area * length;
System.out.println( volume);
}
}
No comments:
Post a Comment