The Java™ Tutorials: Operators
자바강의: 연산자
Operator Precedence
| Operators | Precedence |
|---|---|
| postfix | expr++ expr-- |
| unary | ++expr --expr +expr -expr ~ ! |
| multiplicative | * / % |
| additive | + - |
| shift | << >> >>> |
| relational | < > <= >= instanceof |
| equality | == != |
| bitwise AND | & |
| bitwise exclusive OR | ^ |
| bitwise inclusive OR | | |
| logical AND | && |
| logical OR | || |
| ternary | ? : |
| assignment | = += -= *= /= %= &= ^= |= <<= >>= >>>= |
관계연산자 : 두 피연산자 사이의 값을 크기 또는 관계를 비교하는 연산자로서 true, false 로 구분한다.
관계 연산자의 종류는 다음과 같다.
|
연산자 |
연산식 |
설명 |
|
> |
A > B |
A이 B보다 크면 참 |
|
>= |
A >= B |
A이 B보다 크거나 같으면 참 |
|
< |
A < B |
A이 B보다 작으면 참 |
|
<= |
A <= B |
A이 B보다 작거나 같으면 참 |
|
== |
A == B |
A과 B가 같으면 참 |
|
!= |
A != B |
A과 B가 다르면 참 |
|
instance of |
A instance of B |
A이 B의 인스턴스이면 참 |
논리연산자 : 두개의 논리값을 평가하여 true, false 의 논리형 결과를
반환하는 연산자를 말한다.
|
연산자 |
연산식 |
설명 |
|
! |
!A |
A가 거짓(false)이면 참(true) |
|
&& |
A&&B |
A과 B가 모두 참이면 참 |
|
|| |
A|| B |
A이나 B 둘 중
하나라도 참이면 참 |
|
& |
A & B |
A과 B가 모두 참이면 참 |
|
| |
A | B |
A이나 B 둘 중
하나라도 참이면 참 |
연산자의 우선 순위는 다음과 같다.
연산자의 수행 시 여러 연산자가 혼용된 경우 연산자의 우선순위에 따라 수행하도록 한다.
|
1 |
( ), [ ] |
|
2 |
++, --, ~, (+), (-) |
|
3 |
*, / ,% |
|
4 |
+, - |
|
5 |
>>, <<, >>> |
|
6 |
<, <=, >=, > |
|
7 |
==, != |
|
8 |
& |
|
9 |
^ |
|
10 |
| |
|
11 |
&& |
|
12 |
|| |
|
13 |
expr?op1:op2 |
|
14 |
=, +=,-=, *=, /=, %= |
Operator Purpose +addition of numbers, concatenation of Strings +=add and assign numbers, concatenate and assign Strings -subtraction -=subtract and assign *multiplication *=multiply and assign /division /=divide and assign %take remainder %=take remainder and assign ++increment by one --decrement by one >greater than >=greater than or equal to <less than <=less than or equal to !boolean NOT !=not equal to &&boolean AND ||boolean OR ==boolean equals =assignment ~bitwise NOT ?:conditional instanceoftype checking |bitwise OR |=bitwise OR and assign ^bitwise XOR ^=bitwise XOR and assign &bitwise AND &=bitwise AND and assign >>shift bits right with sign extension >>=shift bits right with sign extension and assign <<shift bits left <<=shift bits left and assign >>>unsigned bit shift right >>>=unsigned bit shift right and assign
참고:
'프로그래밍' 카테고리의 다른 글
| [안드로이드] 프로젝트 구성 디렉토리 (0) | 2012.07.07 |
|---|---|
| [자바] APCS ArrayList Notes (0) | 2012.07.04 |
| 아스키코드 표 (ASCII Code Chart) (0) | 2012.06.21 |
| [자바] 소설같은 자바교재: 자북 (0) | 2012.06.13 |
| [자바] JAVA 강의 노트 (0) | 2012.06.13 |