<<< Back to Homepage

JAVA CODES


Code for calculating the circumference and area of a circle when the radius is provided by the user:



    package circleinputapp;
    import java.util.Scanner; // Importing scanner

    public class CircleInputApp {

        public static void main(String[] args) {
       
        Scanner input = new Scanner(System.in); // Creating scanner object

            double PI = 3.14; // Constant Pi value
            double radius; // Creating new variable radius

        System.out.print("Please enter the radius of the circle: ");

            radius = input.nextDouble(); // Getting user input and storing the value in radius

        System.out.println("The circumference of the circle with radius " + radius + " cm is " + 2 * PI * radius + " cm");
        System.out.println("The area of the circle with radius " + radius + " cm is " + PI * radius * radius + " sq cm");
    }
}