Java Challenge - 2

CYSSSSSSSSS·2024년 3월 4일

자바 챌린지

목록 보기
2/11

Java Challenge

조건식

백준 1330

  • 두 수를 입력 받아 비교하는 프로그램을 작성하시오
package 조건식;

import java.util.Scanner;

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

        int a,b;
        a = scanner.nextInt();
        b = scanner.nextInt();

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

백준 9498

  • 시험 점수를 받아 성적에 맞는 알파벳으로 바꾸시오
package 조건식;

import java.util.Scanner;

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

        int score = scanner.nextInt();

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

백준 2753

  • 년도를 입력받고 윤년이면 1 아니면 0을 출력하는 프로그램을 작성하시오
package 조건식;

import java.util.Scanner;

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

        int year = scanner.nextInt();

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

백준 14681

  • 점 (x,y)의 정보를 한줄씩 입력받아 해당 좌표가 어느 사분면에 해당하는지 출력하시오
package 조건식;

import java.util.Scanner;

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

        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int answer = 0;
        if (x > 0 && y > 0){
            answer = 1;
        } else if (x < 0 && y > 0) {
            answer = 2;
        } else if (x < 0  && y < 0) {
            answer = 3;
        } else {
            answer = 4;
        }
        System.out.println(answer);
    }
}

백준 2884

  • 현재 시간에 대한 정보를 시와 분까지만 입력받은 다음 해당 시간에서 45분 전 시간을 출력하는 프로그램을 작성하시오.
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 < 0){
            if (h == 0){
                h = 23;
                m += 60;
            }else {
                h--;
                m += 60;
            }
            m -= 45;
        } else{
            m -= 45;
        }

        System.out.println(h + " " + m);
    }
}

백준 2525

  • 시작하는 시간과 경과 시간을 알려줬을때, 끝나는 시간을 계산하는 프로그램을 작성하시오
package 조건식;

import java.util.Scanner;

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

        int h = scanner.nextInt();
        int m = scanner.nextInt();

        int m_ = scanner.nextInt();

        int convertHour = (m + m_) / 60;
        int convertMin = (m + m_) % 60;

        if (h + convertHour > 23){
            h = (h + convertHour) % 24;
        } else {
            h = h + convertHour;
        }
        m = convertMin;
        System.out.println(h + " " + m);
    }
}

백준 2480

  • 주사위 3개의 정보를 입력받아 세 개가 같을때,두 개만 같을때,한 개만 같을때에 맞는 상금을 출력하시오

주사위 상금 규칙
1.같은 눈이 3개가 나오면 10,000원+(같은 눈)×1,000원의 상금을 받게 된다.
2.같은 눈이 2개만 나오는 경우에는 1,000원+(같은 눈)×100원의 상금을 받게 된다.
3.모두 다른 눈이 나오는 경우에는 (그 중 가장 큰 눈)×100원의 상금을 받게 된다.

package 조건식;

import java.util.Scanner;

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

        int max = 0;
        int []dices = new int[3];
        int answer = 0;
        for(int i = 0; i<dices.length;i++){
            dices[i] = scanner.nextInt();
            if (max < dices[i]){
                max = dices[i];
            }
        }

        if (dices[0] == dices[1] && dices[1] == dices[2]) {
            answer = 10000 + dices[0] * 1000;
        } else if (dices[0] == dices[1]) {
            answer = 1000 + dices[0] * 100;
        } else if (dices[1] == dices[2]) {
            answer = 1000 + dices[1] * 100;
        } else if (dices[2] == dices[0]) {
            answer = 1000  + dices[2] * 100;
        } else if(dices[0] != dices[1] && dices[1] != dices[2] && dices[2] != dices[0]){
            answer = 100 * max;
        }

        System.out.println(answer);
    }
}
profile
개발자 되고 싶어요

0개의 댓글