[java] 백준 단계별로 풀어보기 2단계알고리즘/백준2021. 6. 17. 21:26
Table of Contents
1단계 1330번 두 수 비교하기
import java.util.Scanner;
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("<");
}
}
2단계 9498번 시험 성적
import java.util.Scanner;
class Main {
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int score = sc.nextInt();
if(90 <= score && score <= 100)
System.out.println("A");
else if(80 <= score && score < 90)
System.out.println("B");
else if(70 <= score && score < 80)
System.out.println("C");
else if(60 <= score && score < 70)
System.out.println("D");
else
System.out.println("F");
}
}
3단계 2753번 윤년
import java.util.Scanner;
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");
}
}
4단계 14681번 사분면 고르기
import java.util.Scanner;
class Main{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
if(a>0 && b>0)
System.out.println("1");
else if(a<0 && b>0)
System.out.println("2");
else if(a<0 && b<0)
System.out.println("3");
else
System.out.println("4");
}
}
5단계 2884번 알람 시계
import java.util.Scanner;
class Main{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int hour = sc.nextInt();
int minute = sc.nextInt();
int a = minute - 45;
if(a < 0){
if(hour==0){
hour=23;
a = minute + 15;
System.out.println(hour+" "+a);
}else{
hour = hour - 1;
a = minute + 15;
System.out.println(hour+" "+a);
}
}else{
System.out.println(hour+" "+a);
}
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[java] 백준 단계별로 풀어보기 3단계 (3) (0) | 2021.06.24 |
---|---|
[java] 백준 단계별로 풀어보기 3단계 (2) (0) | 2021.06.23 |
[java] 백준 단계별로 풀어보기 3단계 (1) (0) | 2021.06.19 |
[java] 백준 단계별로 풀어보기 1단계 (2) (0) | 2021.06.17 |
[java] 백준 단계별로 풀어보기 1단계 (1) (0) | 2021.06.17 |
@펄찌 :: Pearl's Story
펄의 일상이 궁금한 사람 요기~
즐거운 하루 되셨으면 좋겠습니다😊