JavaStudy/Basic
[Java] 4.연산자(operator)
LeeDaniel
2024. 10. 18. 17:16
[ 산술연산자 ]
-산술연산자는 수학적인 계산에 사용되는 연산자이다
기호 의미 + 더하기 - 빼기 * 곱하기 / 나누기 % 나머지 System.out.println( 9 + 3 ); // 결과 : 12 System.out.println( 9 - 3 ); // 결과 : 6 System.out.println( 9 * 3 ); // 결과 : 27 System.out.println( 9 / 3 ); // 결과 : 3 System.out.println( 9 % 3 ); // 결과 : 0
[ 단항 연산자 ]
-하나의 항을 대상으로 연산이 이루어지는 연산자
기호 의미 + 양수를 표현, 생략 가능 - 음수를 표현 ++ 증가(increment) 연산자, 항의 값을 1씩 증가
전위형(prefix) : 항의 앞에 위치 할 경우
즉시 연산
후위형(postfix) : 항의 뒤에 위치 할 경우
다음 행에서 연산-- 감소(decrement) 연산자, 항의 값을 1씩 감소
전위형(prefix) : 항의 앞에 위치 할 경우
즉시 연산
후위형(postfix) : 항의 뒤에 위치 할 경우
다음 행에서 연산int a = 10; System.out.println( a ); // 결과 : 10 System.out.println( -a ); // 결과 : -10 // 전위형(prefix) 증가 연산자, 결과 : 11 System.out.println( ++a ); // 후위형(postfix) 증가 연산자, 결과 : 11 System.out.println( a++ ); // 후위형(postfix) 감소 연산자, 결과 : 12 System.out.println( a-- ); // 전위형(prefix) 감소 연산자, 결과 : 10 System.out.println( --a );
728x90
반응형