코딩테스트/자바 문제풀이

[새싹: 조건] 백준 1330, 9498, 14681, 2753, 2420

승요나라 2024. 7. 3. 22:26

1330번: 두 수 비교하기

https://www.acmicpc.net/problem/1330

 

# 코드

import java.util.Scanner;

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

        long a = sc.nextLong();
        long b = sc.nextLong();

        if (a > b) {
            System.out.println(">");
        } else if (a < b) {
            System.out.println("<");
        } else {
            System.out.println("==");
        }
    }
}

 

 


9498번: 시험 성적

https://www.acmicpc.net/problem/9498

 

# 코드

import java.util.Scanner;

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

        long score = sc.nextLong();

        if (score >= 90 && score <= 100) {
            System.out.println("A");
        } else if (score >= 80 && score < 90) {
            System.out.println("B");
        } else if (score >= 70 && score < 80) {
            System.out.println("C");
        } else if (score >= 60 && score < 70) {
            System.out.println("D");
        } else {
            System.out.println("F");
        }
    }
}

 

 


14681번: 사분면 고르기

https://www.acmicpc.net/problem/14681

 

# 코드

import java.util.Scanner;

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

        long x = sc.nextLong();
        long y = sc.nextLong();

        if (x > 0 && y > 0) {
            System.out.println("1");
        } else if (x < 0 && y > 0) {
            System.out.println("2");
        } else if (x < 0 && y < 0) {
            System.out.println("3");
        } else {
            System.out.println("4");
        }
    }
}

 

 


2753번: 윤년

https://www.acmicpc.net/problem/2753

 

# 코드

import java.util.Scanner;

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

        long year = sc.nextLong();

        if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
            System.out.println("1");
        } else {
            System.out.println("0");
        }
    }
}

 

 


2420번: 사파리월드

https://www.acmicpc.net/problem/2420

 

# 코드

import java.util.Scanner;

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

        long n = sc.nextLong();
        long m = sc.nextLong();

        if (n >= m) {
            System.out.println(n - m);
        } else {
            System.out.println(m - n);
        }
    }
}