» » » Basic Java program to find area and perimeter of circle

1.Write a Basic java example  program to find area of circle

  •  To calculate the area of circle we need to ask user to enter radius of the circle so that we can calculate area of circle using formula area of circle =PI* radius * radius



  1. package com.BasicJavaProgramsExamples;
  2. import java.util.Scanner;
  3. public Class AreaOfCirle{ 
  4.  
  5. public static void main(String args[]) {
  6.  
  7. int radius = 0;
  8. Scanner in= new Scanner(System.in);
  9. System.out.println("Please enter radius of a circle");
  10.  
  11.     radius=in.nextInt();
  12.      
  13. /*
  14.  * where r is a radius of a circle then Area of a circle is
  15.  *Area= pi * r * r
  16.  *
  17.  */
  18.          
  19.     double area=Math.PI* radius * radius;
  20.       
  21.     System.out.println("Area of the circle ="+area);
  22.  
  23. }
  24. }

Output:

  1. Please enter radius of a circle
  2. 23
  3. Area of the circle =1661.9025137490005




2.Write a Basic java example program to find perimeter of circle

  •  To calculate the perimeter  of circle we need to ask user to enter radius of the circle so that we can calculate perimeter  of circle using formula area of circle =2* PI* radius
  
  1. package com.BasicJavaProgramsExamples;
  2. import java.util.Scanner;
  3. public Class PerimeterOfCirle{ 
  4.  
  5. public static void main(String args[]) {
  6.  
  7. int radius = 0;
  8. Scanner in= new Scanner(System.in);
  9. System.out.println("Please enter radius of a circle");
  10.  
  11.     radius=in.nextInt();
  12.      
  13. /*
  14.  * where r is a radius of a circle then perimeter of a circle is
  15.  *Area= pi * r * r
  16.  *
  17.  */
  18.          
  19.     double perimeter =2* Math.PI* radius;
  20.  
  21.     System.out.println("Perimeter of the circle ="+perimeter );
  22.  
  23. }
  24. }

Output:

  1. Please enter radius of a circle
  2. 12
  3. Perimeter of the circle =75.39822368615503

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu