본문 바로가기
Algorithm(알고리즘)/Java

Java 백준 단계별 풀기 (기초 문법 정리) if문

by Jun_N 2020. 12. 22.

1330 두 수 비교하기

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();
        if (A > B) {
            System.out.println(">");
        } else if (A == B) {
            System.out.println("==");
        } else {
            System.out.println("<");
        }
    }
}

 

2753 윤년

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        if (A % 4 == 0 && (A % 100 != 0 || A % 400 == 0)) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }
}

 

2884 알람 시계

import java.util.Scanner;

public class Main {
    public static void main(String[]args){
        Scanner scanner = new Scanner(System.in);

        int H = scanner.nextInt();
        int M = scanner.nextInt();

        if(M<45){
            H--;
            M = 60 - (45-M);
            if(H<0){
                H=23;
            }
            System.out.println(H+" "+M);
        }else{
            System.out.println(H+" "+(M-45));
        }
    }
}