Object-Oriented Programming with Java, part I – Exercise 10

Exercise 10

This program asks the user for the radius and then calculates the circumference of a circle (2*pi*r) using the given radius.

My code


import java.util.Scanner;

public class Circumference {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);

        // Program your solution here 
        System.out.println("Type the radius: ");
        int radius = Integer.parseInt(reader.nextLine());
        
        System.out.println("Circumference of the circle: " + (2 * Math.PI * radius));
    }
}

Model code

import java.util.Scanner;

 

public class Circumference {

    public static void main(String[] args) {

        Scanner reader = new Scanner(System.in);

 

        // Program your solution here 

        System.out.print("Type the radius: ");

        int radius = Integer.parseInt(reader.nextLine());

 

        System.out.println(""); 

        System.out.println("Circumference of the circle: " + (2 * Math.PI * radius));

    }

}
Leave a Reply

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