본문 바로가기

JAVA-BAEKJOON/2단계 조건문

(7)
[백준/02-07] 2480 주사위 세 개 NO.2480 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n1 = sc.nextInt(); int n2 = sc.nextInt(); int n3 = sc.nextInt(); sc.close(); // 모두 다른 눈이 나오는 경우 if(n1!=n2 && n2!=n3 && n3!=n1) { int max; // max 설정하기 // 1. n1>n2 => n1>n2, n3 or n3>n1>n2 if(n1>n2) { if(n3>n1) { max = n3; }else { max = n1; } } // 2. n2>n1 =>..
[백준/02-06] 2525 오븐 시계 NO.2525 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int m = sc.nextInt(); int c = sc.nextInt(); sc.close(); if (m+c>=60) { h = h + (m+c)/60; m = (m+c)%60; if (h>23) { h = h-24; } System.out.println(h + " " + m); } else { System.out.println(h + " " + (m+c)); } } } 📌생각보다 일찍 틀린 문제가 나와서 속상.. 너무..
[백준/02-05] 2884 알람 시계 NO.2884 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt();// 시 int m = sc.nextInt();// 분 sc.close(); if(m
[백준/02-04] 14681 사분면 고르기 NO.14681 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); if(x>0) { if(y>0) { System.out.println(1); } else System.out.println(4); } else { if(y>0) { System.out.println(2); } else{ System.out.println(3); } } } } 📌 아직 코드가 짧고 숫자형들이라 그런가 scanner 가 작성하기 너무 편하다.. 편식하면 안되는데.. 일단 ..
[백준/02-03] 2753 윤년 NO.2753 풀이코드 import java.util.Scanner; public class _2753 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int Year = scanner.nextInt(); System.out.println(((Year%4==0 && Year%100!=0) || (Year%4==0 && Year%400==0))? 1 : 0); } } 📌 Year%4==0 의 중복이 신경쓰인다... 다시 재도전 import java.util.Scanner; public class _2753 { public static void main(String[] args) { Scanner scan..
[백준/02-02] 9498 시험 성적 NO.9498 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int score = scanner.nextInt(); scanner.close(); System.out.println((score>=90) ? "A" : (score>=80) ? "B" : (score>=70) ? "C" : (score>=60) ? "D" : "F"); } } 📌 02-01 풀이시 봤던 삼항연산자 중첩을 적용해봤다. 확실히 여러줄 써야할 것을 한줄만 쓰니 편해서 비슷한 문제를 풀 때는 이렇게 풀어야겠다.
[백준/02-01] 1330 두 수 비교하기 NO.1330 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int A = scanner.nextInt(); int B = scanner.nextInt(); scanner.close(); if(A>B) { System.out.println(">"); } else if(AB) { System.out.println(">"); } else if(AB) ? ">" : ((A