Write a simple program to find a perimeter and area of circle.......
By entering the value of radius by user......
In Java
Please use scanner class....
Don't spam......
Answers
Answer:
- int main() { int rad;
- float PI = 3.14, area, ci; printf("\nEnter radius of circle: ");
- scanf("%d", &rad); area = PI * rad * rad;
- printf("\nArea of circle : %f ", area); ci = 2 * PI * rad;
- printf("\nCircumference : %f ", ci); return (0);
Answer:
❥
/*Java program to create class to calculate area and perimeter of circle.*/
import java.util.*;
class AreaOfCircle
{
private float radius=0.0f;
private float area=0.0f;
private float perimeter=0.0f;
//function to read radius
public void readRadius()
{
//Scanner class - to read value from keyboard
Scanner sc=new Scanner(System.in);
System.out.print("Enter radius:");
radius=sc.nextFloat(); //to read float value from keyboard
}
//funtction to calculate area
//return value - will return calculated area
public float getArea()
{
area= Math.PI *radius*radius;
return area;
}
//funtction to calculate perimeter
//return value - will return calculated perimeter
public float getPerimeter()
{
perimeter = 2* Math.PI *radius;
return perimeter;
}
}
public class circle
{
public static void main(String []s)
{
AreaOfCircle area=new AreaOfCircle();
area.readRadius();
System.out.println("Area of circle:" + area.getArea());
System.out.println("Perimeter of circle:" + area.getPerimeter());
}
}
Explanation:
Write a Java program to print the area and perimeter of a circle.
In geometry, the area enclosed by a circle of radius r is πr2. Here the Greek letter π represents a constant, approximately equal to 3.14159, which is equal to the ratio of the circumference of any circle to its diameter.
The circumference of a circle is the linear distance around its edge.
if this is wrong then report ok
yes you can search more about this on Google ok