본문 바로가기

Baekjoon/브론즈 510

[백준][JAVA/자바] 11382번: 꼬마 정민 - while 문 써서 해결하는 방법 브론즈 5 11382번: 꼬마 정민 첫 번째 줄에 A, B, C (1 ≤ A, B, C ≤ 1012)이 공백을 사이에 두고 주어진다. www.acmicpc.net (1) 간단한 방법 사용 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long sum = 0; Long a = scanner.nextLong(); Long b = scanner.nextLong(); Long c = scanner.nextLong(); sum = a + b + c; System.out.println(sum); } } (2) while 문 사용 //.. 2023. 12. 19.
[백준][JAVA/자바] 11718번: 그대로 출력하기 브론즈 5 11718번: 그대로 출력하기 입력이 주어진다. 입력은 최대 100줄로 이루어져 있고, 알파벳 소문자, 대문자, 공백, 숫자로만 이루어져 있다. 각 줄은 100글자를 넘지 않으며, 빈 줄은 주어지지 않는다. 또, 각 줄은 공백으로 시 www.acmicpc.net import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); while (s.hasNext()) { String input = s.nextLine(); System.out.println(input); } s.close(); } } (1) 런타임 에러 (NoSuchElement) .. 2022. 12. 14.
[백준][JAVA/자바] 11022번: A+B - 8 브론즈 5 11022번: A+B - 8 각 테스트 케이스마다 "Case #x: A + B = C" 형식으로 출력한다. x는 테스트 케이스 번호이고 1부터 시작하며, C는 A+B이다. www.acmicpc.net import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int num = s.nextInt(); for (int i = 0; i < num; i++) { int a = s.nextInt(); int b = s.nextInt(); System.out.println("Case #" + (i + 1) + ": " + a + " + " + b.. 2022. 12. 14.
[백준][JAVA/자바] 11021번: A+B - 7 브론즈 5 11021번: A+B - 7 각 테스트 케이스마다 "Case #x: "를 출력한 다음, A+B를 출력한다. 테스트 케이스 번호는 1부터 시작한다. www.acmicpc.net import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int num = s.nextInt(); for (int i = 0; i < num; i++) { int a = s.nextInt(); int b = s.nextInt(); System.out.println("Case #" + (i + 1) + ": " + (a + b)); } s.close(); } } 2022. 12. 12.
[백준][JAVA/자바] 10952번: A+B - 5 브론즈 5 10952번: A+B - 5 두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오. www.acmicpc.net (1) while 문 조건으로 .hasNextInt() 개념 사용 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); while (s.hasNextInt()) { int a = s.nextInt(); int b = s.nextInt(); if (a == 0 && b == 0) { break; } else { System.out.println(a + b); } } } } (2) while 문 조건으.. 2022. 12. 9.
[백준][JAVA/자바] 10951번: A+B - 4 브론즈 5 10951번: A+B - 4 두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오. www.acmicpc.net import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); while (s.hasNextInt()) { int a = s.nextInt(); int b = s.nextInt(); System.out.println(a + b); } } } (1) hasNextInt() 2022. 12. 2.