-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprac_set9.java
More file actions
50 lines (50 loc) · 1.29 KB
/
prac_set9.java
File metadata and controls
50 lines (50 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
class cylinder{
public cylinder(){
this.radius=1;
this.height=1;
}
public cylinder(int h,int r)
{
this.radius=r;
this.height=h;
}
float radius,height;
final float pi= 3.14F;
Scanner sc=new Scanner(System.in);
public void setRad(){
System.out.println("Enter radius of the cylinder(in cm): ");
radius=sc.nextFloat();
}
public void setHt(){
System.out.println("Enter height of the cylinder(in cm): ");
height=sc.nextFloat();
}
public float getRad()
{
return radius;
}
public float getHt()
{
return height;
}
public float surfaceArea()
{
return (2*pi*radius*height)+(2*pi*radius*radius);
}
public float volume()
{
return (pi*radius*radius*height);
}
}
public class prac_set9 {
public static void main(String[] args) {
cylinder c=new cylinder(12,9);
//c.setRad();
//c.setHt();
System.out.println("Radius = "+c.getRad()+" cm");
System.out.println("Height = "+c.getHt()+" cm");
System.out.println("Surface Area = "+c.surfaceArea()+" sq.cm");
System.out.println("Volume = "+c.volume()+" cube cm");
}
}