다음 Java 코드는 직경, 호 길이, 둘레 및 면적을 얻기 위해 getDiameter(), getLength(), getLengthArc() 및 getSurface().
public class Circle {
중심점;
정적 이중 반경;
public Circle(중심점, 이중 반경){
this.center=center;
this.radius=반지름;
}
정적 이중 getDiametre(){
반환 반경*2;
}
정적 이중 getLength(){
2*3.14*radius를 반환합니다.
}
정적 이중 getSurface(){
return 3.14*Math.pow(radius, 2);
}
정적 double getLengthArc(이중 알파){
3.14*alpha를 반환합니다.
}
public static void main(String[] args) {
Circle = new Circle(new Point(0, 0), 8);
System.out.println("지름: "+Circle.getDiameter());
System.out.println("길이: "+Circle.getLength());
//각도가 55 라디안인 호 길이
이중 알파 = 55;
System.out.println("호 길이: "+Circle.getArcLength(55));
System.out.println("표면: "+Circle.getSurface());
}
}
Output
직경: 16.0
둘레: 50.24
호 길이: 172.7000000000000002
면적: 200.96