-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3_CircleMeasurements.java
More file actions
48 lines (42 loc) · 1.23 KB
/
Copy pathQ3_CircleMeasurements.java
File metadata and controls
48 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.*;
public class Q3_CircleMeasurements
{
public static double pi=3.1416;
static double distance(double x1,double y1,double x2,double y2)
{
return (Math.sqrt( ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) ) );
}
static double radius(double x1,double y1,double x2,double y2)
{
return ( Math.sqrt( ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) ) );
}
static double circumference(double r)
{
return (2 * pi * r);
}
static double area(double r)
{
return (pi * r * r);
}
public static void main(String args[])
{
double x1,x2,y1,y2;
double d,r,c,a;
Scanner sc =new Scanner(System.in);
System.out.println("Enter the first point (x1,y1) ");
x1=sc.nextDouble();
y1=sc.nextDouble();
System.out.println("Enter the second points (x2,y2) ");
x2=sc.nextDouble();
y2=sc.nextDouble();
d=distance(x1,y1,x2,y2);
System.out.printf("Distance between two given points is %.3f \n",d);
r=radius(x1,y1,x2,y2);
System.out.printf("Radius of the circle is %.3f \n",r);
System.out.printf("Diameter of the circle is %.3f \n",2*r);
c=circumference(r);
System.out.printf("Circumference of the circle is %.3f \n", c );
a=area(r);
System.out.printf("Area of circle is %.3f square units\n", a);
}
}