백준알고리즘 2단계 if문_java

1330번_두 수 비교하기_step01

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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("==");
		}
	}
}


9498번_시험 성적_step02

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.Scanner;

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

		int score = sc.nextInt();

		if(score<=100&&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번_윤년_step03

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.util.Scanner;

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

		int year = sc.nextInt();

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

		else
		{
			System.out.println("0");
		}
	}
}


2884번_알람 시계_step04

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;

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

		int h = sc.nextInt();//시간
		int m = sc.nextInt();//분


		if(m<45) {
			if(h==0) {
				h=24;
			}
	     	h-=1;
			m+=15;
			System.out.println(h+" "+m);
		}
		else {
			m-=45;
			System.out.println(h+" "+m);
		}
	}
}

여기서 조심해야할 부분은 시(hour)가 00이고 분(minute)이 45분이하이면 시가 23시가 되어야한다.

10817번_세 수_step05

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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();
		int c=sc.nextInt();

		if((b>=a&&a>c)||(c>a&&a>b)) {
			System.out.println(a);
		}
		else if((a>b&&b>=c)||(c>b&&b>a)) {
			System.out.println(b);
		}

		else {
			System.out.println(c);
		}
	}
}