1056 : [기초-논리연산] 참/거짓이 서로 다를 때에만 참 출력하기
import java.util.*;
public class Main{
public static void main(String arg[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a ^ b);
}
}
1057 : [기초-논리연산] 참/거짓이 서로 같을 때에만 참 출력하기
import java.util.*;
public class Main {
public static void main(String arg[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a == b? 1 : 0);
}
}
1058 : [기초-논리연산] 둘 다 거짓일 경우만 참 출력하기
import java.util.*;
public class Main {
public static void main(String arg[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a == 0 && b == 0? 1 : 0);
}
}
1059 : [기초-비트단위논리연산] 비트단위로 NOT 하여 출력하기
import java.util.*;
public class Main {
public static void main(String arg[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
System.out.println(~a);
}
}
1060 : [기초-비트단위논리연산] 비트단위로 AND 하여 출력하기
import java.util.*;
public class Main {
public static void main(String arg[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a & b);
}
}
새롭게 알게된 점
비트 단위 NOT(~) 연산은 피연산자의 모든 비트 값을 반전시키는 연산
비트 단위 AND 연산(&)은 두 개의 비트가 모두 1일 때만 결과로 1을 반환하고, 둘 중 하나라도 0이면 0을 반환하는 연산
XOR(^) 연산 꼭 기억하자.

'Algorithm > 코드업' 카테고리의 다른 글
| [코드업 기초 100제] Java 1051 ~1055 풀이 (0) | 2025.08.31 |
|---|---|
| [코드업 기초 100제] Java 1046 ~1050 풀이 (1) | 2025.08.30 |
| [코드업 기초 100제] Java 1041 ~1045 풀이 (0) | 2025.08.30 |
| [코드업 기초 100제] Java 1036 ~1040 풀이 (0) | 2025.08.30 |
| [코드업 기초 100제] Java 1031 ~1035 풀이 (1) | 2025.08.19 |