본문 바로가기

코드조각모음

[Java004] 상수 사용하기

package com.java.tutorial.circlearea;

public class CircleArea
{
    static final float PI = 3.141592f;
   
    public static float getCircleArea(float radius)
    {
        return 2.0f * radius * PI;
    }
   
    public static void main(String[] args)
    {
        System.out.printf("circle area of 1 radius : %f\n", getCircleArea(1.0f));
        System.out.printf("circle area of 2 radius : %.3f\n", getCircleArea(2.0f));
    }
}

출력결과
circle area of 1 radius : 6.283184
circle area of 2 radius : 12.566