0

How can i write a java program that will read the radius and height of a cylinder and compute the volume using the formulas Area= raduis*raduis*3.14159 and Volume= area*height, and have the program report the area of the bottom of the cylinder and the voulme of the cylinder.

4
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by k-broxe
0

what program are you trying to run ? please make it specified so that we can help you .

0

This looks like a homework assignment.

You will have to figure out how to create a class with a "main" method, and to run it.

You will have to figure out how to print data to the user (System.out.println), and receive data from the user. (Using a "scanner" is popular.)

The math is trivial. In the program, it will be similar to what you've written above.

-1

you can use this code

import java.util.*;
public class sususususususususus {

	public static Scanner kev=new Scanner(System.in);
	public static void main(String[] args) {
			Scanner kev = new Scanner (System.in);
			//int choice=0 ,again;
			
			System.out.println("Choose what shape do you want [1]cylinder [2]sphere [3]Quit:");
			int k=kev.nextInt();
			
			switch(k){
				case 1:
					cylinder();
					break;
				case 2:
					sphere();
					break;
				case 3:
					System.out.println("You Quit");
					System.out.println("Thank You!!!(^_^)!!!");
					System.exit(k);
					
			}
			
	}
	static void cylinder(){
		System.out.println("Enter radius: ");
		double radius = kev.nextDouble();
		System.out.println("Enter height: ");
		double height = kev.nextDouble();
		System.out.println(radius*radius*Math.PI*height+" square units");
	}
	static void sphere(){
		System.out.println("Enter radius:");
		double radius = kev.nextDouble();
		System.out.println((4/3)*radius*radius*radius*Math.PI+ " Square units");
	}

}

Edited by peter_budo: Keep It Clear - Do use code tags when posting any code

Comments
One would have to be really desperate to use such badly written program
This article has been dead for over six months. Start a new discussion instead.
Please be thoughtful and detailed and be sure to adhere to our posting rules.