Write a program to calculate the area of the sphere and a cyinder? ( using mathematical functions )
Answers
Answer:
import java.util.Scanner;
class area {
public static void main(String Args[]) {
Scanner sc = new Scanner(System.in);
double r1, r2, h;
// Taking input from the user about radius of the sphere
System.out.print("Enter radius of the sphere: ");
r1 = sc.nextDouble();
// calculating area of the sphere
double sphere = 4 * Math.PI * Math.pow(r1, 2);
// displaying the area of the sphere
System.out.format("Area of the sphere is: %.2f \n", sphere);
// Taking input from the user about radius and height of the cylinder
System.out.print("Enter radius of the cylinder: ");
r2 = sc.nextDouble();
System.out.print("Enter the height of the cylinder: ");
h = sc.nextDouble();
// calculating area of the cylinder
double cylinder = 2 * Math.PI * r2 * (r2 + h);
// displaying the area of the cylinder
System.out.format("Area of the cylinder is: %.2f \n", cylinder);
}
}
Please don't forget to mention the language