Find Area Of The Circle Taking Radius From The User | Java Programs

Output:

*** Area Of Circle ***

Enter the radius of circle: 
10
The Radius Of Circle is: 10.0
The Area Of Circle is: 314.150

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class AreaOfCircle {

    void findArea(double x) {
        double z = 3.1415 * x * x;  //3.1415 is the value of PI
        //Or this can be written as:
        //double z = Math.PI * x * x;

        System.out.print("The Radius Of Circle is: " + x);
        System.out.println("\nThe Area Of Circle is: " + z);
    }

    public static void main(String args[]) {
        AreaOfCircle area = new AreaOfCircle();
        Scanner sc = new Scanner(System.in);
        System.out.println("*** Area Of Circle ***" + "\n");
        System.out.println("Enter the radius of circle: ");
        int radius = sc.nextInt();
        area.findArea(radius);
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon