January 22, 2022



Write Java Code and Run

1 min read

Online Java Compiler.

Code, Compile, Run and Debug java program online.

Write your code in this editor and press “Run” button to execute it.

Sample Solution:

Write a Java program to print the area and perimeter of a circle.

In geometry, the area enclosed by a circle of radius r is πr2. Here the Greek letter π represents a constant, approximately equal to 3.14159, which is equal to the ratio of the circumference of any circle to its diameter.

The circumference of a circle is the linear distance around its edge.

Pictorial Presentation:

Java area and perimeter of a circle

Why is the area of a circle of a circle pi times the square of the radius? 

Why is the area of a circle of a circle pi times the square of the radius?

Java Code:

import java.util.Scanner;
public class Main {
 public static void main(String[] args) {
  Scanner io = new Scanner(System.in);
  System.out.println("Input the radius of the circle: ");
  double radius = io.nextDouble();
  System.out.println("Perimeter is = " + (2 * radius * Math.PI));
  System.out.println("Area is = " + (Math.PI * radius * radius));


Input the radius of the circle:   5 
Perimeter is = 31.41592653589793
Area is = 78.53981633974483


Flowchart: Java exercises: Find the area and perimeter of a circle

Leave a Reply

Your email address will not be published. Required fields are marked *