In this task, you are being asked to write a given word problem as a program.
Write a program that prompts the user for a radius and then prints:
- The area and circumference of a circle with that radius
- The volume and surface area of a sphere with that radius
NOTE: Use Math class constants and functions in your program.
Code:
import java.util.Scanner;
public class lab4Task5{
public static void main(String[] args) {
Scanner Ahsan = new Scanner(System.in);
double area, CircumFarance, volum, Surfac, radius;
System.out.print("Enter the Radius: ");
radius = Ahsan.nextDouble();
area = Math.PI * Math.pow(radius, 2);
CircumFarance = 2 * Math.PI * radius;
volum =(int) (4 / 3) * Math.PI * Math.pow(radius, 3);
Surfac = 4 * Math.PI * Math.pow(radius, 3);
System.out.println("Area of the Circle is: " + area);
System.out.println("The CircumFarance of the Circle is: " + CircumFarance);
System.out.println("The Volume of the Circle is: "+ volum);
System.out.println("The SurfacArea of the Circle is: " + Surfac);
}
}
OutPut:
| Convert word problem into Java code |
No comments:
Post a Comment