In this Java programming tutorial, we will make a Java program to calculate the area of a circle, if any users enters the radius of that circle. It is a very simple and basic Java problem, in which we will take radius as a input from the user and after that just simply apply the mathematical formula to calculate radius in the program code, which is π * r² that is pi times the square of the radius of circle.
Java Program to Calculate Area of Circle
/* Program to find the area of any circle by Codext */ import java.util.Scanner; // using Scanner class to get input from user public class CalculateCircleArea { public static void main(String[] args) { System.out.println("Enter the radius of circle:"); Scanner num = new Scanner(System.in); int radius = num.nextInt(); System.out.println("The radius of the circle is " + radius); double area = Math.PI * radius * radius; System.out.println("Area of a circle is " + area); } } /* Area of a circle is pi * r * r where r is a radius of a circle. */ // NOTE :We have used Math.PI constant to get value of pi

0 comments:
Post a Comment