6-Write a program to calculate the area of a circle. Use the formula Pi * r * r to work the program. Remember Pi is a constant and r is a variable entered by the user at runtime (once the program is running). Format the answer to 2 decimal places.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Radius: ");
double radius = in.nextDouble();
System.out.printf("Area: %.2f", Math.PI * radius * radius);
}
}
Comments
Leave a comment