Write a Java program to input radius of a circle from user and find diameter, circumference and area of the circle. How to calculate diameter, circumference and area of a circle whose radius is given by user in Java programming. Logic to find diameter, circumference and area of a circle in Java.

**Required knowledge**

Arithmetic operators, Data types, Defining constants, Basic input/output

**Properties of circle**

Diameter, circumference and area of a circle formula is given by -

Where r is radius of the circle.

**Logic to find diameter, circumference and area of circle**

Below is the step by step descriptive logic to find diameter, circumference and area of a circle -

Input radius of circle from user. Store it in a variable say radius.

Apply the formulas to calculate diameter, circumference and area. Use diameter = 2 * radius, circumference = 2 * 3.14 * radius and area = 3.14 * radius * radius.

Print all resultant value diameter, circumference and area.

**Program to find diameter, circumference and area of circle**

/** * Java program to calculate diameter, circumference and area of circle */ import java.util.Scanner; class Test { public static void main(String args[]) { double radius, diameter, circumference, area; Scanner op=new Scanner(System.in); /* * Input radius of circle from user */ System.out.print("Enter radius of circle: "); radius=op.nextDouble(); /* * Calculate diameter, circumference and area */ diameter = 2 * radius; circumference = 2 * 3.14 * radius; area = 3.14 * (radius * radius); /* * Print all results */ System.out.println("Diameter of circle = "+diameter+" units "); System.out.println("Circumference of circle = "+circumference+" units "); System.out.println("Area of circle = "+area+" sq. units "); } }

**Output:**

Enter radius of circle: 5 Diameter of circle = 10.0 units Circumference of circle = 31.400000000000002 units Area of circle = 78.5 sq. units

**Program to find diameter, circumference and area of circle using PI constant**

/** * Java program to calculate diameter, circumference and area of circle */ import java.util.Scanner; class Test1 { public static void main(String args[]) { double radius, diameter, circumference, area,M_PI; Scanner op=new Scanner(System.in); /* * Input radius of circle from user */ System.out.print("Enter radius of circle: "); radius=op.nextDouble(); M_PI=22/7; /* * Calculate diameter, circumference and area of circle */ diameter = 2 * radius; circumference = 2 * M_PI * radius; area = M_PI * (radius * radius); /* * Print all results */ System.out.println("Diameter of circle = "+diameter+" units"); System.out.println("Circumference of circle = "+circumference+" units "); System.out.println("Area of circle = "+area+" sq. units "); } }

**Output:**

Enter radius of circle: 20 Diameter of circle = 40.0 units Circumference of circle = 120.0 units Area of circle = 1200.0 sq. units