F How to calculate Circle area in Java programming? | CodeTheta

How to calculate Circle area in Java programming?

March 15, 2018

Code :
package demo;
import java.util.Scanner;
/*
 * @author www.CodeTheta.com
 */
public class Demo {
    public static void main(String[] args) {
    double CircleArea,Radius;
    double Pi=3.14;
    System.out.println("Enter radius of a circle: ");
    Scanner in = new Scanner(System.in);
    Radius = in.nextInt();
    CircleArea = Pi * Radius * Radius;
    System.out.println("Area of a circle is: "+CircleArea);   
    }   
}

Above program calculating Circle area through user input during program execution time.

Output :
Area of a circle is: 28.259999999999998

Code :
package demo;
/*
 * @author www.CodeTheta.com
 */
public class Demo {
    public static void main(String[] args) {
    double CircleArea,Radius = 3;
    double Pi=3.14;
    CircleArea = Pi * Radius * Radius;
    System.out.println("Area of a circle is: "+CircleArea);   
    }   

}

Above program calculating Circle area through user defined input.

Output :
Area of a circle is: 28.259999999999998


IDE Used To Test This Code : NetBeans IDE 8.2

 Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment