A Program to Find the Area of a Circle

In this example, we are giving a program to find the area of a circle. The rule of finding the area of a circle is: A = πr2.


Program to find the area of a circle:

  1. import java.util.Scanner; //Scanner class helps to get input from user
  2. class circle {
  3. public static void main(String[] args) {
  4. Scanner s = new Scanner(System.in); //Scanner class object declaration
  5. System.out.println("Enter the value of radius: ");
  6. float r = s.nextFloat(); // takes float input radius from keyboard or user or run time
  7. float area = (3.14*r*r);
  8. System.out.println("Area of Circle: "+ area);
  9. }
  10. }

Output:

Enter the value of radius: 3
Area of Circle: 28.26