Computer Science, asked by arunsharmah4, 3 months ago

Write a java program to accept the radius and height from the user to calculate & display the:

1. Diameter of a CIRCLE
(d=2×radius)

2. Circumference of a CIRCLE (circumference=2πr)

3. Area of a CIRCLE
(Area=πr²)



4. Surface Area of a CYLINDER (surface area=2πrh+2πr²)

5. Volume of a CYLINDER (volume=πr²h)

Use ceil method to display the values.​

Answers

Answered by AestheticSoul
43

★ Program :-

import java.util.*;

class circle

{

public static void main(String agrs[])

{

int r, h;

Scanner in = new Scanner (System.in);

System.out.println("Enter '1' to calculate the diameter of a circle, '2' to calculate the circumference of a circle, '3' to calculate the area of a circle, '4' to calculate surface area of a cylinder and '5' to calculate volume of a cylinder");

System.out.println("Enter your choice");

int ch = in.nextInt( );

switch (ch)

{

case 1 : System.out.println("Enter the radius of the circle");

r = in.nextInt( );

System.out.println("Diameter of circle =" + Math.ceil(2*r));

break;

case 2 : System.out.println("Enter the radius of the circle");

r = in.nextInt( );

System.out.println("Circumference of circle =" + Math.ceil((22/7)*r*r));

break;

case 3 : System.out.println("Enter radius of the circle");

r = in.nextInt( );

System.out.println("Area of circle =" + Math.ceil((22/7)*r*r));

break;

case 4 : System.out.println("Enter radius and height of the cylinder");

r = in.nextInt( );

h = in.nextInt( );

System.out.println("Surface area of cylinder =" + Math.ceil(2*(22/7)*r*h + 2*(22/7)*r*r));

break;

case 5 : System.out.println("Enter radius and height of the cylinder");

r = in.nextInt( );

h = in.nextInt( );

System.out.println("Volume of cylinder =" + Math.ceil((22/7)*r*r*h));

break;

default : System.out.println("Wrong choice");

}

}

}

▬▬▬▬▬▬▬▬▬▬▬▬▬▬

Output :-

Refer to the attached image.

Input number = 10 [Case - 1]

Attachments:
Similar questions