백준 14681번 (조건문)
import java.util.Scanner;
public class problem52 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 간단한 구현 문제다
int a = in.nextInt();
int b = in.nextInt();
if(a > 0 && b > 0){
System.out.println(1);
} else if (a < 0 && b > 0) {
System.out.println(2);
} else if (a > 0 && b < 0) {
System.out.println(4);
}else{
System.out.println(3);
}
}
}
백준 2884번 (조건문)
import java.util.Scanner;
public class problem53 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int hour = in.nextInt();
int minute = in.nextInt();
int temp = 0;
// 분이 45분 이상일때
if (minute >= 45) {
temp = minute - 45;
System.out.print(hour + " " + temp);
}
// 분이 45분 보다 작을때
else if (minute < 45) {
// 분이 45분보다 작고, 시간이 0이 입력되었을경우
if (hour == 0) {
int a = 23;
int b = minute + 60 - 45;
System.out.println(a + " " + b);
} else {
int c = minute + 60 - 45;
System.out.println(hour - 1 + " " + c);
}
}
}
}
백준 2525번 (조건문)
import java.util.Scanner;
public class problem54 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int hour = in.nextInt();
int minute = in.nextInt();
int inputTime = in.nextInt();
// 시간 --> 분 변환
int minSum = 60 * hour + minute;
minSum += inputTime;
// 전체 시각을 분으로 변화하고, 1시간이 60분이고, 하루가 24시간임으로
int totalHour = (minSum / 60) % 24;
int totalMin = minSum % 60;
System.out.println(totalHour + " " + totalMin);
}
}
백준 25304번 (반복문)
import java.util.Scanner;
public class problem55 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int total = in.nextInt();
int count = in.nextInt();
// 물건의 가격과 갯수를 입력받고, total 가격에서 빼준다.
for (int i = 0; i < count; i++) {
int a = in.nextInt();
int b = in.nextInt();
total -= a * b;
}
if(total == 0){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}
백준 10807번 (1차원 배열)
import java.util.Scanner;
public class problem56 {
public static void main(String[] args) {
// 간단한 배열 문제다.
Scanner in = new Scanner(System.in);
int size = in.nextInt();
int [] array= new int[size];
int count = 0;
for (int i = 0; i < size; i++) {
array[i] = in.nextInt();
}
// 입력된 숫자와 match 하여 같으면 count 증가
int match = in.nextInt();
for (int i = 0; i < size; i++) {
if(array[i] == match){
count++;
}
}
System.out.println(count);
}
}