전체 글

전체 글

    [JAVA 기초] 조건, 대입 연산자

    조건연산자 삼항(조건) 연산자는 조건식, 식1, 식2 모두 세 개의 피연산자를 필요로 하는 삼항 연산자이며, 삼항 연산자는 조건 연산자 하나뿐이다. public static void main(String[] args) { int x, y, z; int absX, absY, absZ; char signX, signY, signZ; x = 10; y = -5; z = 0; absX = x>=0 ? x : -x; absY = y>=0 ? y : -y; absZ = z>=0 ? z : -z; signX = x > 0 ? '+' : (x==0 ? ' ' : '-'); signY = y > 0 ? '+' : (y==0 ? ' ' : '-'); signZ = z > 0 ? '+' : (z==0 ? ' ' : '-')..

    [JAVA 기초] 쉬프트 연산자(shift operator)

    쉬프트 연산자 (>)는 피 연산자의 각 자리를 오른쪽(>>) 왼쪽( 0, toBinaryString(dec >> 0)); System.out.printf("%d >> %d = %4d \t%s%n", dec, 1, dec >> 1, toBinaryString(dec >> 1)); System.out.printf("%d >> %d = %4d \t%s%n", dec, 2, dec >> 2, toBinaryString(dec >> 2)); System.out.printf("%d > %d = %4d \t%s%n", dec, 1, dec >> 1, toBinaryString(dec >> 1)); System.out.printf("%d >> %d = %4d \t%s%n", dec, 2, dec >> 2, toBina..

    [JAVA 기초] 비트 전환 연산자

    비트 전환 연산자 ~ 비트 전환 연산자는 2진수로 표현했을 때, 0은 1 1은 0으로 표현한다. x ~x 1 0 0 1 public static void main(String[] args) { byte p = 10; byte n = -10; System.out.printf("p = %d \t%s%n", p, toBinaryString(p)); System.out.printf("~p = %d \t%s%n", ~p, toBinaryString(~p)); System.out.printf("~p+1 = %d \t%s%n", ~p+1, toBinaryString(~p+1)); System.out.printf("~~p = %d \t%s%n", ~p+1, toBinaryString(~~p)); System.out.p..

    [JAVA 기초] 논리 부정 연산자(true, false)

    논리 부정 연산자 x !x true false false true public static void main(String[] args) { int x = 0xAB, y = 0xF; System.out.printf("x = %#X \t\t%s%n", x, toBinaryString(x)); System.out.printf("y = %#X \t\t%s%n", x, toBinaryString(y)); System.out.printf("%#X | %#X = %#X \t%s%n", x, y, x | y, toBinaryString(x | y)); System.out.printf("%#X & %#X = %#X \t%s%n", x, y, x & y, toBinaryString(x & y)); System.out.pr..

    [JAVA 기초] 논리연산자(&&, ||, !)

    논리연산자 &&, ||, ! x는 5보다 크고, 10보다 작다. x > 10 && x < 20 i는 2의 배수 또는 3의 배수이다. i%2==0 || i%3==0 i는 2의 배수 또는 3의 배수지만 6의 배수는 아니다. (i%2==0 || i%3==0) && i%6!=0 문자 ch는 숫자 (0~9)이다. '0'