728x90 반응형 Coding Test/CodeUp78 CodeUp_Java 기초 100제 - [기초-비트단위논리연산] 비트단위로 NOT 하여 출력하기 59 //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); //System.out.print("정수 1개 입력 : "); int a = sc.nextInt(); sc.close(); //입력받은 정수에 NOT연산 System.out.println(~a); } } 2022. 2. 10. CodeUp_Java 기초 100제 - [기초-논리연산] 둘 다 거짓일 경우만 참 출력하기 58(설명) //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); if(a == 0 && b == 0){ //둘 다 거짓일 경우 System.out.println(1); } else{ //그 외의 경우 System.out.println(0); } } } 2022. 2. 8. CodeUp_Java 기초 100제 - [기초-논리연산] 참/거짓이 서로 같을 때에만 참 출력하기 57(설명) //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); if((a == 1 && b == 1) || (a == 0 && b == 0)){ //a, b의 값이 같은 경우 System.out.println(1); } else{ //a, b의 값이 서로 다른 경우 System.out.println(0); } } } 2022. 2. 8. CodeUp_Java 기초 100제 - [기초-논리연산] 참/거짓이 서로 다를 때에만 참 출력하기 56(설명) //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); System.out.print("정수 2개 입력(0, 1) : "); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); if((a == 1 && b == 0) || (a == 0 && b == 1)){ //a와 b의 값이 다른 경우 System.out.println(1); } else{ //a와 b의 값이 다른 경우 System.out.println(0); } } } 2022. 2. 8. CodeUp_Java 기초 100제 - [기초-논리연산] 하나라도 참이면 참 출력하기 55(설명) //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); //System.out.print("정수 2개 입력 : "); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); if(a == 1 || b == 1){ //a와 b 중 하나라도 1인 경우 System.out.println(1); } else{ //a와 b가 둘 다 0인 경우 System.out.println(0); } } } 2022. 2. 8. CodeUp_Java 기초 100제 - [기초-논리연산] 둘 다 참일 경우만 참 출력하기 54(설명) //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); System.out.print("정수 2개 입력(0, 1) : "); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); if(a == 1 && b == 1){ //a와 b 둘다 1인 경우 System.out.println(1); } else{ //a와 b가 모두 1이 아닌 경우 System.out.println(0); } } } 2022. 2. 8. CodeUp_Java 기초 100제 - [기초-논리연산] 참 거짓 바꾸기 53(설명) //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); //System.out.print("정수 1개 입력 : "); int a = sc.nextInt(); sc.close(); if(a == 0){//a가 0이면 a = 1; } else{//a가 1이면 a = 0; } System.out.println(a); } } 2022. 2. 8. CodeUp_Java 기초 100제 - [기초-비교연산] 두 정수 입력받아 비교하기(4) 52(설명) //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); System.out.print("정수 2개 입력 : "); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); if(a != b){ //a와 b가 다르면 System.out.println(1); } else{ //a와 b가 같으면 System.out.println(0); } } } 2022. 2. 7. CodeUp_Java 기초 100제 - [기초-비교연산] 두 정수 입력받아 비교하기(3) 51(설명) //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); System.out.print("정수 2개 입력 : "); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); if(b>=a){ //b가 a보다 크거나 같으면 System.out.println(1); } else{ //b가 a보다 작으면 System.out.println(0); } } } 2022. 2. 7. CodeUp_Java 기초 100제 - [기초-비교연산] 두 정수 입력받아 비교하기(2) 50(설명) //자바코드 import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); System.out.print("정수 2개 입력 : "); int num1 = sc.nextInt(); int num2 = sc.nextInt(); sc.close(); if(num1==num2){ //두 정수가 같으면 System.out.println(1); } else{ //두 정수가 다르면 System.out.println(0); } } } 2022. 2. 7. 이전 1 2 3 4 5 6 ··· 8 다음 728x90 반응형