본문 바로가기

분류 전체보기69

[백준 8393번 - java] 합 https://www.acmicpc.net/submit/8393/35033117 내 답안 (오답) import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { int i = 0; int sum = 0; Scanner s = new Scanner(System.in); int n = s.nextInt(); for (i=1; i 2021. 11. 3.
[백준 10950번 - java] A + B - 3 https://www.acmicpc.net/problem/10950 내 답안 import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { int i = 0; Scanner s = new Scanner(System.in); int T = s.nextInt(); for (i=1; i 2021. 11. 3.
[백준 2739번 - java] 구구단 https://www.acmicpc.net/problem/2739 내 답안 import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { int i = 0; Scanner s = new Scanner(System.in); int N = s.nextInt(); for (i=1; i 2021. 11. 3.
[백준 2884번 - java] 알람 시계 https://www.acmicpc.net/problem/2884 내 답안 import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); int H = s.nextInt(); int M = s.nextInt(); int H_new = 0; int M_new = 0; if (M>=45) { H_new = H; M_new = M-45; System.out.printf("%d %d", H_new, M_new); } else { H_new = H-1; M_new = 60-(45-M); if (H_new.. 2021. 11. 3.
[백준 14681번 - java] 사분면 고르기 https://www.acmicpc.net/problem/14681 내 답안 import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); if (a>0 && b>0) { System.out.println("1"); } else if (a>0 && b 2021. 11. 3.
[백준 1330번 - java] 두 수 비교하기 https://www.acmicpc.net/problem/1330 내 답안 import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); if (a>b) { System.out.println(">"); } else if (a 2021. 11. 3.
[백준 9498번 - java] 시험 성적 https://www.acmicpc.net/problem/9498 내 답안 import java.io.*; import java.util.*; public class Main{ public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); int score = s.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.. 2021. 11. 3.
[백준 2753번 - java] 윤년 https://www.acmicpc.net/problem/2753 내 답안 import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); int year = s.nextInt(); if ((year%4 == 0) && ((year%100 != 0) || (year%400 == 0))) { System.out.println("1"); } else System.out.println("0"); } } 또 다른 풀이 방법들 - 이중 if문 사용 - A.compareTo(B) 사용 (A가 B 보다 크면 .. 2021. 11. 3.
[Java] next()와 nextLine() 차이점 Scanner 클래스의 String을 입력받는 메서드 next()와 nextLine() Scanner의 next()는 화이트스페이스를 기준으로 입력을 받는다. 화이트스페이스(whitespace)란? 의미없는 공백, 탭, 행 등 (' ', '\t', '\r', '\n' 등) next()와 nextLine() 차이점 next() '한 단어'를 기준으로 읽어들인다. = 공백을 기준으로 입력을 받는다. nextLine() '한 줄'을 기준으로 읽어들인다 = 개행을 기준으로 입력을 받는다. 2021. 11. 2.