1.Write a Basic java example program to find area of circle
Output:
2.Write a Basic java example program to find perimeter of circle
Output:
- 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
- package com.BasicJavaProgramsExamples;
- import java.util.Scanner;
- public Class AreaOfCirle{
- public static void main(String args[]) {
- int radius = 0;
- Scanner in= new Scanner(System.in);
- System.out.println("Please enter radius of a circle");
- radius=in.nextInt();
- /*
- * where r is a radius of a circle then Area of a circle is
- *Area= pi * r * r
- *
- */
- double area=Math.PI* radius * radius;
- System.out.println("Area of the circle ="+area);
- }
- }
Output:
- Please enter radius of a circle
- 23
- 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
- package com.BasicJavaProgramsExamples;
- import java.util.Scanner;
- public Class PerimeterOfCirle{
- public static void main(String args[]) {
- int radius = 0;
- Scanner in= new Scanner(System.in);
- System.out.println("Please enter radius of a circle");
- radius=in.nextInt();
- /*
- * where r is a radius of a circle then perimeter of a circle is
- *Area= pi * r * r
- *
- */
- double perimeter =2* Math.PI* radius;
- System.out.println("Perimeter of the circle ="+perimeter );
- }
- }
Output:
- Please enter radius of a circle
- 12
- Perimeter of the circle =75.39822368615503
No comments