JAVA

[프로그래머스 자바 입문] 상수

전감자(◔◡◔) 2022. 11. 17. 11:00
package javastudy;

public class ConstantExam {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int i;
		i = 10;
		i = 5;
		
		final int J;// 상수는 대문자로 명명한다.
		J = 10;
		// J = 5; => 불가
		
		double circleArea;
		final double PI = 3.141592;
		//circleArea = 3 * 3 * 3.141592;
		circleArea = 3 * 3 * PI;
		
		final int OIL_PRICE = 1450;
		// 상수는 모두 대문자로 쓰는 것이 관례이기 때문에 단어사이를 언더바 (_)로 구분해준다.
		
		int totalPrice = 50 * OIL_PRICE;

✅상수는 final 키워드를 사용해 선언.

✅상수는 대문자로만 씁니다.