JAVA/STUDY

2. 변수, 상수, 연산자

dev_sr 2020. 9. 8. 14:38

변수선언 할 때 String 은 앞을 대문자로 함

상수선언 할 때는 final을 붙여줌


public class Main {

	//상수
	final static double PI = 3.141592;
	
	public static void main(String[] args) {
		
		//변수
		int intType = 100;
		double doubleType = 150.5;
		String stringType = "홍길동";	//string 대문자
		
		System.out.println(intType);
		System.out.println(doubleType);
		System.out.println(stringType);

		//상수
		int r = 30;
		System.out.println(r*r*PI);
		
		
		//연산
		int a = 5;
		int b = 3;
		
		System.out.println("a+b=" +(a+b));
		System.out.println("a-b=" +(a-b));
		System.out.println("a*b=" +(a*b));
		System.out.println("a/b=" +(a/b));
		System.out.println("a%b=" +(a%b));
		
		//캐스팅 반올림
		float c = 0.6f;
		int d = (int)(0.5+c);
		System.out.println(d);
		
		
	}

}

'JAVA > STUDY' 카테고리의 다른 글

6. 반복문과 재귀함수 (팩토리얼, 피보나치)  (0) 2020.09.09
5. 입력 / 파일 입력  (0) 2020.09.09
4. 조건문 & 반복문  (0) 2020.09.08
3. 자료형(데이터 타입)  (0) 2020.09.08
1. 개발 환경 설치 및 출력 메서드  (0) 2020.09.08