영원히 흘러가는 강
코드업 100제 (1051~1055) 본문
728x90
1051 .두 정수(a, b)를 입력받아
b가 a보다 크거나 같으면 1을, 그렇지 않으면 0을 출력하는 프로그램을 작성해보자.
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int y=sc.nextInt();
if(x<=y)
System.out.println("1");
else
System.out.println("0");
}}
1052 .두 정수(a, b)를 입력받아
a와 b가 서로 다르면 1을, 그렇지 않으면 0을 출력하는 프로그램을 작성해보자.
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int y=sc.nextInt();
if(x!=y)
System.out.println("1");
else
System.out.println("0");
}}
1053. 1(true, 참) 또는 0(false, 거짓) 이 입력되었을 때
반대로 출력하는 프로그램을 작성해보자. (입력된 값이 0이면 1, 1이면 0을 출력한다.)
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
if(x==1)
System.out.println("0");
else if(x==0)
System.out.println("0");
else
System.out.println(x);
}}
1054. 두 개의 참(1) 또는 거짓(0)이 입력될 때,
모두 참일 때에만 참을 출력하는 프로그램을 작성해보자.
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int y=sc.nextInt();
if(x==1 && y==1 )
System.out.println("참");
else
System.out.println("거짓");
}}
1055. 두 개의 참(1) 또는 거짓(0)이 입력될 때,
하나라도 참이면 참을 출력하는 프로그램을 작성해보자.
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int y=sc.nextInt();
if(x==1 || y==1 )
System.out.println("참");
else
System.out.println("거짓");
}}
728x90
'알고리즘' 카테고리의 다른 글
코드업 100제 (1061~1065) (0) | 2020.09.22 |
---|---|
코드업 100제 (1056~1060) (0) | 2020.09.22 |
코드업 100제 (1046~1050) (0) | 2020.09.22 |
코드업 100제 (1041~1045) (0) | 2020.09.22 |
코트업 100제 (1036~1040) (0) | 2020.09.21 |
Comments