Last Updated:

Circle area and circle length in Java

  1. The program asks the user to enter the radius of the circle
  2. No user interaction: The radius value will be specified in the program itself.

Circle area in Java. Enter the radius manually

/* Program for calculating the area of ​​a circle and the circumference of a circle.
The radius is entered by the user. The program will ask
The user will enter the radius into the console and display the results of the calculations.
*/
import java.util.Scanner;
public class CircleProgram {
static Scanner sc = new Scanner(System.in);
public static void main(Stringargs[])
{
System.out.print("Enter radius: ");
/* We store the entered radius in double
because the user can enter the radius as a fractional number
*/
double radius = sc.nextDouble();
//The area of ​​a circle is calculated using the formula = PI*radius*radius
double area = Math.PI * (radius * radius);
System.out.println("The area of ​​the circle is: " + area);
//Circumference is calculated by the formula = 2*PI*radius
double circumference= Math.PI * 2*radius;
System.out.println("The circumference is: " + circumference) ;
}
}

The result of the program:

 

Circle area and circle length in Java. The radius value is specified in the program

 

The result of the second program: