#1330 두 수 비교하기

* 풀이
import java.util.*;
public class Main{
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.print(">");
} else if(A < B){
System.out.print("<");
} else{
System.out.print("==");
}
}
}
# 9498 시험 성적

* 풀이
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int score = sc.nextInt();
if(90 <= score && score <= 100){
System.out.print("A");
} else if(80 <= score && score < 90){
System.out.print("B");
} else if(70 <= score && score < 80){
System.out.print("C");
} else if(60 <= score && score < 70){
System.out.print("D");
} else{
System.out.print("F");
}
}
}
# 2754 윤년

* 풀이
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)){
System.out.print("1");
} else{
System.out.print("0");
}
}
}
# 14681 사분면 고르기


* 풀이
import java.util.*;
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 > 0 && y > 0){
System.out.print("1");
} else if(x < 0 && y > 0){
System.out.print("2");
} else if(x < 0 && y < 0){
System.out.print("3");
} else if(x > 0 && y < 0){
System.out.print("4");
}
}
}
# 2884 알람시계

* 풀이
import java.util.Scanner;
public class Main {
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 = m + 60 - 45;
if (h < 0) {
h = 23;
}
} else {
m = m - 45;
}
System.out.println(h + " " + m);
}
}
if (minute < 45) {
hour = hour - 1;
현재 분에서 45를 빼서 음수가 됐을 때 시(h)도 1시간 줄여야 함
if (hour < 0) {
hour = 23;
시(h)가 음수가 되면 23시로 (자정 바로 전)
else문
그냥 분에서 45를 빼면 됨
* 다른 풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int H = sc.nextInt(); // 시
int M = sc.nextInt(); // 분
sc.close();
if (M >= 45) {
M -= 45;
} else {
H -= 1; // 한 시간 감소
M += 15; // 60 - 45 = 15 더하기
if (H < 0) { // 0시에서 1시간 빼면 -1 → 23시 처리
H = 23;
}
}
System.out.println(H + " " + M);
}
}
# 2525 오븐 시계


* 풀이
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int min = (a * 60) + b;
min += c;
a = min / 60;
b = min % 60;
if(a > 23){
a = a - 24;
}
System.out.print(a + " " + b);
}
}
시를 분으로 바꾼 후 다 더한 다음에 60으로 다시 나눴다.
if문을 통해 시가 24 이상일 경우 24를 빼서 0, 1 ~~ 시가 될 수 있도록 한다.
* 다른 풀이
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(); // 현재 분
int c = sc.nextInt(); // 요리 시간 (분 단위)
// 총 분 계산
int totalMin = A * 60 + B + C;
// 종료 시각
int H = totalMin / 60;
int M = totalMin % 60;
if (H >= 24) {
H = H % 24; // 24시 넘으면 0시로 환산
}
System.out.println(H + " " + M);
}
}
# 2480 주사위 세개


* 풀이
import java.util.*;
public class Main{
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 && b == c){
System.out.print(10000 + a * 1000);
} else if(a == b || a == c){
System.out.print(1000 + a * 100);
} else if(b == c){
System.out.print(1000 + b * 100);
} else{
int max = a;
if(max < b){
max = b;
}if(max < c){
max = c;
}
System.out.print(max * 100);
}
}
}
'코테 > 백준' 카테고리의 다른 글
| [백준 / java 11] 2741번 N 찍기 (0) | 2025.05.01 |
|---|---|
| [백준 / java 11] 반복문 > 2739번 구구단 (0) | 2025.04.29 |
| [백준 / java 11] 입출력과 사칙연산 > 10926번, 18108번, 10430번, 11382번, 10171번, 10172번 (0) | 2025.04.27 |
| [백준 / java 11] 입출력과 사칙연산 > 1008번 A/B (0) | 2025.04.24 |
| [백준 / java 11] 입출력과 사칙연산 > 1000 A+B, 1001 A-B, 2258 A+B -2 (0) | 2024.11.14 |