Language/Java
데이터와 연산자
뚜sh뚜sh
2023. 6. 30. 22:16
상수
- 사용하고 있는 모든 수, 불변의 값
- 숫자 상수(정수형 상수, 부동소수점형 상수)와 문자 상수("a", "B", 유니코드 등)
package first;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.printf("%1$d %2$d",(int)'3', (int)'A');
}
}
// 51 65 (유니코드)
데이터형
- 기본형 : boolean, char, byte, short, int, long, float
- 참조형(reference type)
- 메모리 주소를 저장하는 데이터형(type) -> 클래스, 배열, 인터페이스
- 4 bype 크기
변수
- 상수를 저장하는 메모리 공간
- 형식 -> C언어와 동일(데이터형 변수명;)
package first;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean bVar = true;
int nVar = 12;
float fVar = 3.14f;
char cVar = 'j';
System.out.println("bool형 : " + bVar + " 정수형 : " + nVar);
System.out.println("부동소수점형 : " + fVar + " 문자상수 : " + cVar);
}
}
연산자
- 산술 연산, 비교 연산 등에 사용되는 키워드 -> C언어와 동일
package first;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int nVar1, nVar2, nResult;
nVar1 = 5;
nVar2 = 6;
nResult = nVar1 + nVar2;
System.out.println(nResult);
System.out.println(12 > 4);
System.out.println(12 == 4);
System.out.println((12 > 4) && (12 == 4));
}
}