Question
calculate the area of circle.
Area of circle=π*radius of circle*radius of circle
π=3.1415926535897.... taking pi upto 2 decimal places
radius of circle=10cm
then,
area of circle==3.14*10*10=314sq cm
Enter the radius of circle
12
Area of circle=452.15999999999997
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class areaOfCircle
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the radius of circle");
double r=sc.nextDouble();
//pi=3.1415926535897.... taking pi upto 2 decimal places
double pi=3.14;
/*Formula of area of circle =pi*r*r */
double area=pi*r*r;
System.out.println("Area of circle="+area);
}
}