티스토리 뷰

1053 : [기초-논리연산] 참 거짓 바꾸기

import java.util.Scanner;

// 210125
// 1053 : [기초-논리연산] 참 거짓 바꾸기

public class CU1053 {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int num = sc.nextInt();
        System.out.println((num==1? 0: 1));

        sc.close();
    }
}

 

1054 : [기초-논리연산] 둘 다 참일 경우만 참 출력하기

import java.util.Scanner;

// 210125
// 1054 : [기초-논리연산] 둘 다 참일 경우만 참 출력하기

public class CU1054 {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println((a==1&&b==1)? 1: 0);

        sc.close();
    }
}

 

1055 : [기초-논리연산] 하나라도 참이면 참 출력하기

import java.util.Scanner;

// 210125
// 1055 : [기초-논리연산] 하나라도 참이면 참 출력하기

public class CU1055 {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println((a==1||b==1)? 1: 0);

        sc.close();
    }
}

 

1056 : [기초-논리연산] 참/거짓이 서로 다를 때에만 참 출력하기

import java.util.Scanner;

// 210125
// 1056 : [기초-논리연산] 참/거짓이 서로 다를 때에만 참 출력하기

public class CU1056 {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        // int -> boolean 
        boolean b1 = sc.nextInt()!=0;
        boolean b2 = sc.nextInt()!=0;

        System.out.println((b1!=b2)? 1: 0);

        sc.close();
    }
}

 

1057 : [기초-논리연산] 참/거짓이 서로 같을 때에만 참 출력하기

import java.util.Scanner;

// 210125
// 1057 : [기초-논리연산] 참/거짓이 서로 같을 때에만 참 출력하기

public class Main {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        // int -> boolean 
        boolean b1 = sc.nextInt()!=0;
        boolean b2 = sc.nextInt()!=0;

        System.out.println((b1^b2)? 0: 1);

        sc.close();
    }
}

 

1058 : [기초-논리연산] 둘 다 거짓일 경우만 참 출력하기

import java.util.Scanner;

// 210125
// 1058 : [기초-논리연산] 둘 다 거짓일 경우만 참 출력하기

public class CU1058 {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        // int -> boolean 
        boolean b1 = sc.nextInt()!=0;
        boolean b2 = sc.nextInt()!=0;

        System.out.println(!(b1||b2)? 1: 0);

        sc.close();
    }
}

 

1059 : [기초-비트단위논리연산] 비트단위로 NOT 하여 출력하기

import java.util.Scanner;

// 210125
// 1059 : [기초-비트단위논리연산] 비트단위로 NOT 하여 출력하기

public class CU1059 {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int num = sc.nextInt();

        System.out.println(~num);

        sc.close();
    }
}

 

1060 : [기초-비트단위논리연산] 비트단위로 AND 하여 출력하기

import java.util.Scanner;

// 210125
// 1060 : [기초-비트단위논리연산] 비트단위로 AND 하여 출력하기

/*     비트단위(bitwise)연산자
    ~(bitwise not), &(bitwise and), |(bitwise or), ^(bitwise xor),
    <<(bitwise left shift), >>(bitwise right shift) 
*/

public class CU1060 {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(a & b);

        sc.close();
    }
}

 

1061 : [기초-비트단위논리연산] 비트단위로 OR 하여 출력하기

import java.util.Scanner;

// 210125
// 1061 : [기초-비트단위논리연산] 비트단위로 OR 하여 출력하기

public class CU1061 {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(a | b);

        sc.close();
    }
}

 

1062 : [기초-비트단위논리연산] 비트단위로 XOR 하여 출력하기

import java.util.Scanner;

// 210125
// 1062 : [기초-비트단위논리연산] 비트단위로 XOR 하여 출력하기

public class CU1062 {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(a ^ b);

        sc.close();
    }
}

'코딩테스트 > 코드업' 카테고리의 다른 글

[CodeUp] 1405 : 숫자 로테이션  (0) 2021.01.26
[CodeUp] 100제 - 1063 ~1077  (0) 2021.01.25
[CodeUp] 1515 : 생명 게임 1  (0) 2021.01.25
[CodeUp] 100제 - 1093 ~1099  (0) 2021.01.25
[CodeUp] 100제 - 1087 ~ 1092  (0) 2021.01.23
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함