티스토리 뷰

Algorithm

[JAVA] 백준 - if문

ellie.strong 2021. 3. 29. 22:08
728x90

백준 1330 : 두 수 비교하기

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st = new StringTokenizer(br.readLine(), " ");

        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());

        if(A > B) {
            System.out.println(">");
        }
        else if(A < B) {
            System.out.println("<");
        }
        else {
            System.out.println("==");
        }
        /*

        삼항 연산자를 이용한 방법
        String str = (A > B) ? ">" : ((A < B) ? "<" : "==");
        System.out.println(str);

         */
    }
}

 

백준 2884 : 알람 시계

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st = new StringTokenizer(br.readLine(), " ");

        int H = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());

        // 45분 일찍 알람 설정하기
        if(M < 45) {
            M = 60 + (M - 45);
            if(H < 1) H = 23;
            else H -= 1;
        }
        else M -= 45;

        System.out.printf("%d %d\n", H, M);
        // System.out.println(H + " " + M);
    }
}

 

728x90
댓글
공지사항
최근에 올라온 글