Write a Java program to find area and perimeter of circle whose radius is user input
Answers
Explanation:
public class Circle.
int r;
double pi = 3.14, area;
Scanner s = new Scanner(System
.
System. out. print("Enter radius of circle:");
r = s. nextInt()
area = pi * r * r;
System. out. println("Area of circle:"+area);
Answer:
import java.io.*;
class Circle
{
public static void main(String args[])
{
int radius;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the radius of a Circle: ");
String str = br.readLine();
radius = Integer.parseInt(str);
double area, perimeter;
area = 3.14 * radius * radius;
perimeter=2 * 3.14 * radius;
System.out.println("Area of Circle: " + area);
System.out.println("Perimeter of Circle: " + perimeter);
}
catch(Exception e)
{
System.out.println("Error : "+e);
}
}
}
Explanation: