Algorithm

[백준] 3. 반복문 - 25304. 영수증 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int rcpt = sc.nextInt(); // 영수증 금액 int total = sc.nextInt(); // 토탈 개수 int sum = 0; for (int i = 1; i

[백준] 3. 반복문 - 8393. 합 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int j = 0; sc.close(); for (int i = 1; i

[백준] 3. 반복문 - 10950. A+B - 3 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int arr[] = new int[num]; // 배열선언 for (int i = 0; i < num; i++) { int a = sc.nextInt(); int b = sc.nextInt(); arr[i] = a + b; } sc.close(); for (int j : arr) { System.out.println(j); } } } 여러 방법으로 푸는 방법이 있겠지만 나는 배열 원소에 입력받은 a 와 b를 더해주어 i 번째 배열에..

[백준] 3. 반복문 - 2739. 구구단 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); // 몇단 sc.close(); for (int i = 1; i < 10; i++) { System.out.println(num + " * " + i + " = " + num * i); } } } 반복문에서 제일 기초적인 문제이다! 다만 주의할 점이라면 출력에서 보듯이 문자 사이에 공백이 있으니 반드시 유의해야한다. 출처 https://www.acmicpc.net/problem/2739 2739번: 구구단 N을 입력받은 뒤, 구구단 ..

[백준] 2. 조건문 - 2480. 주사위 세개 (Java11)
문제 풀이 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 c = sc.nextInt(); sc.close(); // 1. 만약 모든 변수가 다르면 int max = 0; if (a != b && b != c && a != c) { // 만약 a > b 라면 if (a > b) { // c > a > b 일때 if (c > a) { max = c; } else { max = a; } } else { // c > b > a 일때 if (c > b) {..

[백준] 2. 조건문 - 2525. 오븐 시계 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int hour = sc.nextInt(); // 시간 int min = sc.nextInt(); // 분 int timer = sc.nextInt(); // 요리시간 sc.close(); int Min = 60*hour+min; //시 ->분 Min += timer; int Hour = (Min / 60) % 24; int minute = Min % 60; System.out.println(Hour + " " + minute); } } 알람 시계 문제에서는 주어진 시간에서 ..

[백준] 2. 조건문 - 2884. 알람 시계 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int hour = sc.nextInt(); // 시간 int min = sc.nextInt(); // 분 sc.close(); if (min 45..

[백준] 2. 조건문 - 14681. 사분면 고르기 (Java11)
문제 풀이 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(); sc.close(); if(x>0&&y>0) { System.out.println("1"); }else if(x0) { System.out.println("2"); }else if(x