상수(constant)
상수
형태
public static final double PI = 3.141592;데모 1 : 상수가 필요한 상황
public class ConstantExample01{
public static void main(String[] args){
//키보드 방향키를 다음과 같이 약속
//2(down), 4(left), 6(right), 8(up)
int direction = 2;
switch(direction){
case 2: System.out.println("down"); break;
case 4: System.out.println("left"); break;
case 6: System.out.println("right"); break;
case 8: System.out.println("up"); break;
}
}
}데모 2 : 상수 사용
데모 3 : 별도의 클래스에 상수 배치 및 사용
결론
Last updated