Java Math calculate circle's radius

Question

We would like to calculate circle's radius using Java Math.

import java.util.Scanner;

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

        int r;//  www . java2  s  .  c o m

        System.out.print("Enter a circle's radius: ");
        r = input.nextInt();

        //your code here
    }
}



import java.util.Scanner;

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

        int r;

        System.out.print("Enter a circle's radius: ");
        r = input.nextInt();

        System.out.printf("Diameter = %d\nCircumference = %.2f\nArea = %.2f\n",
                            2 * r, 2 * Math.PI * r, Math.PI * r * r);
    }
}



PreviousNext

Related