small steps/1일 1코딩 - 코딩을 내 몸처럼
[1일1코딩] [Java] 전위 증가 연산자(전치), 후위 증가 연산자(후치)
꿈꾸는개발자maker
2022. 2. 11. 21:50
728x90
public class practice_everyday01 {
public static void main(String[] args) {
// 전위, 후위 증가연산자
// =전치,후치
int a = 1;
int b = 2;
int ab = ++a + b; // (1+1) + 2 = 4 : a=2 b=2 ab=4
int c = 3; // c=3
int ac = a + c--; // 2 + 3 = 5 : a=2 b=2 c=2
int bc = ++b - c; // 3 - 1 = 1 : a=2 b=3 c=2
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(ab);
System.out.println(ac);
System.out.println(bc);
}
}
728x90
반응형