#### 백준 단계별로 풀어보기 (2)
: 조건문
1330번 : 두 수 비교하기
import java.util.Scanner;
public class B1330 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
if(a > b){
System.out.println(">");
}else if(a == b){
System.out.println("==");
}else {
System.out.println("<");
}
}
}
9498번 : 시험성적
import java.util.Scanner;
public class B9498 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int score = sc.nextInt(); // 점수 입력 받기
char grade;
switch (score/10){
case 10,9 -> grade ='A';
case 8 -> grade = 'B';
case 7 -> grade = 'C';
case 6 -> grade = 'D';
default -> grade = 'F';
}
System.out.println(grade);
sc.close();
}
}
2753번 : 윤년
import java.util.Scanner;
public class B2753 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
if(year%4 == 0){ // 4의 배수이고
if(((year % 100) != 0) || (year%400 == 0)){
// 100의 배수가 아닐 때 또는 400의 배수일 때
System.out.println(1);
}else
System.out.println(0);
}else
System.out.println(0);
sc.close();
}
}
14681번 : 사분면 고르기
import java.util.Scanner;
public class B14681 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
if(x > 0 && y > 0) // 1사분면
System.out.println(1);
else if (x < 0 && y > 0) // 2사분면
System.out.println(2);
else if (x < 0 && y < 0) // 3사분면
System.out.println(3);
else if (x > 0 && y <0) // 4사분면
System.out.println(4);
else
System.out.println("다시 입력하세요");
}
2884번 : 알람시계
import java.util.Scanner;
public class B2884_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int m = sc.nextInt();
if (m < 45){
h --;
m = 60-(45-m);
if(h < 0)
h = 23;
System.out.print(h + " " + m);
}else {
System.out.print(h + " " + (m-45));
}
}
}
2525번 : 오븐시계
import java.util.Scanner;
public class B2525 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt(); // 시작하는 시(h)
int m = sc.nextInt(); // 시작하는 분(m)
int time = sc.nextInt(); // 걸리는 시간
m = m+time;
while (m>=60){
h++;
m = m - 60;
if (h == 24)
h = 0;
}
System.out.print(h + " " + m);
}
}
2480번 : 주사위 세개
import java.util.Scanner;
public class B2480 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a= sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a==b){
if(c==b) // 다 같을 때
System.out.println(10000 + a*1000);
else // c만 다를 때
System.out.println(1000 + a*100);
} else if(b==c) // b랑 c만 같을 때
System.out.println(1000 + b*100);
else if (a==c) { // a랑 c만 같을 때
System.out.println(1000 + a*100);
}
else { // 다 다를때
if ( a < c && b < c) // c가 제일 클 때
System.out.println(c*100);
else if(c < b && a < b) // b가 제일 클 때
System.out.println(b*100);
else // a가 제일 클 때
System.out.println(a*100);
}
}
}