Wednesday, January 29, 2014

Calculating the area of a circle.

Source:
import java.util.Scanner;
 
public class CircleArea {
 
   static Scanner sc = new Scanner(System.in);
 
   public static void main(String args[]) {
      System.out.print("Enter the radius of your circle: ");
      double r = sc.nextDouble();
      double area = Math.PI * (r * r);
      System.out.println("The area is " + area);
   }
}

Output:
   $ java CircleArea 
   Enter the radius of your circle: 2
   The area is 12.566370614359172

Blog Archive