본문 바로가기
JAVA/algorithm

[백준] - 두 수 비교, 시험 성적, 윤년, 사분면 (JAVA)

by 개폰지밥 2021. 5. 5.
반응형

If

두 수 비교하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int A;
		int B;
        
		Scanner sc = new Scanner(System.in);
        
		A = sc.nextInt();
		B = sc.nextInt();

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

 

시험 성적

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int A;

		Scanner sc = new Scanner(System.in);
		A = sc.nextInt();

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

 

윤년

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int A;

		Scanner sc = new Scanner(System.in);
		A = sc.nextInt();

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

 

사분면 고르기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int x;
		int y;

		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		y = sc.nextInt();

		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");

	}
}
반응형

댓글