Java Arithmetic Operator calculate circle area with console input

Question

We would like to calculate circle area with console input.

Code structure you can use:


import java.util.Scanner; // Scanner is in the java.util package

public class Main {
  public static void main(String[] args) {
    // Create a Scanner object
    Scanner input = new Scanner(System.in);
    /*from www .j  av  a  2  s  . c o m*/
    // Prompt the user to enter a radius
    System.out.print("Enter a number for radius: ");
    double radius = input.nextDouble();

    //your code here
  } 
}




import java.util.Scanner; // Scanner is in the java.util package

public class Main {
  public static void main(String[] args) {
    // Create a Scanner object
    Scanner input = new Scanner(System.in);
    
    // Prompt the user to enter a radius
    System.out.print("Enter a number for radius: ");
    double radius = input.nextDouble();

    // Compute area
    double area = radius * radius * 3.14159;

    // Display result
    System.out.println("The area for the circle of radius " +
      radius + " is " + area);
  } 
}



PreviousNext

Related