코딩테스트/코드업

[CodeUp] 100제 - 1053 ~ 1062

jhk828 2021. 1. 25. 22:13

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();
    }
}