Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Program Question

Status
Not open for further replies.

Hundley

MIS
Aug 21, 2001
3
US
Hi - I am working on a problem for a java class that I am taking and am having trouble figuring out the answer... here is the question:

"Write a program to compute the volume of a cylinder. Your program reads in radius and lenght, and computes volume using the following formulas:

area = radius*radius*PIE(3.14)
volume = area*lenght"

If anyone has any suggestions it would be greatly appreciated...Thanks!
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class (insert name here) {

public static void main(String[] args) {
try {
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader console = new BufferedReader(reader);

System.out.print("Please enter the radius: ");
String input = console.readLine();
double radius = Double.parseDouble(input);
System.out.print("Please enter the length: ");
String input = console.readLine();
double length = Double.parseDouble(input);

double area = radius*radius*3.14;
System.out.println("The area is " + area + " and the voloume is " + area*length + ".");
}
catch(IOException e) {
System.out.println(e);
System.exit(1);
}
}
}
"and everything under the sun is in tune
but the sun is eclipsed by the moon." --Pink Floyd: Eclipse


"I'm going to spend eternity
reinstalling Windows." --Reinstalling Windows: by some British guy
 
GT500FOMOCO, Don't do his homework for him, then he doesn't learn.

Hundley, what exactly don't you understand about this assignment. It seems easy enough. Mike Wills
RPG Programmer (but learning Java)

"I am bad at math because God forgot to include math.h into my program!"
 
Thank for the info...

My main problem is that I don't really understand this stuff - I am new at programming and am having trouble trying to comprehend exactly what is going on...

I will study this code and hopefully get a better idea...

Thanks again.
 
You should ask your instructor for more help then. He/She should be more than willing to explain things better. Mike Wills
RPG Programmer (but learning Java)

"I am bad at math because God forgot to include math.h into my program!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top