본문 바로가기

백준34

[백준 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.
[백준 2588번 - java] 곱셈 내가 작성한 답안 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 num = 0; num = B % 10; System.out.println(A*num); num = (B/10) % 10; System.out.println(A*num); num = (B/100) % 10; System.out.println(A*num); System.out.println(A*B); } } 아주 원시적이다... 하하 아직은 머릿속으로 떠오르는 알고리즘을 코드로 옮기는 과.. 2021. 11. 2.
[백준 2558번 - java] A+B - 2 https://www.acmicpc.net/problem/2558 내 답안 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int A = s.nextInt(); int B = s.nextInt(); System.out.println(A+B); } } 1000번 문제(https://www.acmicpc.net/problem/1000)와는 다른 점 - 1000번 문제는 두 수를 한 줄에 입력받음 - 2558번 문제는 한 줄에 하나의 수를 입력받음 그러나 Scanner 클래스의 nextInt() 메서드는 공백(space)이나 개행(enter.. 2021. 11. 2.
[백준 1008번 - java] A/B 내 답안 (오답) import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int A = s.nextInt(); int B = s.nextInt(); System.out.println(A/B); } } "상대오차가 10⁻⁹ 이내이면 정답이다." 변수를 소수점 아래 9자리 이상 표현할 수 있는 실수형(double)으로 입력받도록 한다. int형으로 입력받아 계산할 경우, 소수점 아래 단위를 버리고 계산하기 때문에 double형(실수형)으로 입력받아 계산해야 한다. 정답 import java.util.Scanner; public class Main.. 2021. 11. 2.