728x90
반응형
옷가게 할인 받기
/**
* 코딩테스트 입문 Day 5 수학, 배열
* 옷가게 할인 받기
*/
public class Main1 {
public static void main(String[] args) {
System.out.println(solution(150000));
System.out.println(solution(580000));
}
public static int solution(int price) {
if (price >= 500_000) {
price = (int) (price * 0.8);
} else if (price >= 300_000) {
price = (int) (price * 0.9);
} else if (price >= 100_000) {
price = (int) (price * 0.95);
}
return price;
}
}
아이스 아메리카노
/**
* 코딩테스트 입문 Day 5 수학, 배열
* 아이스 아메리카노
*/
public class Main2 {
public static void main(String[] args) {
int[] result = solution(5500);
for (int num : result) {
System.out.print(num + " ");
}
System.out.println();
result = solution(15000);
for (int num : result) {
System.out.print(num + " ");
}
System.out.println();
}
public static int[] solution(int money) {
int[] answer = new int[2];
int price = 5500;
int cnt = money / price;
int changes = money - (price * cnt);
answer[0] = cnt;
answer[1] = changes;
return answer;
}
}
나이 출력
/**
* 코딩테스트 입문 Day 5 수학, 배열
* 나이 출력
*/
public class Main3 {
public static void main(String[] args) {
System.out.println(solution(40));
System.out.println(solution(23));
}
public static int solution(int age) {
int year = 2022;
return year - age + 1;
}
}
배열 뒤집기
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* 코딩테스트 입문 Day 5 수학, 배열
* 배열 뒤집기
*/
public class Main4 {
public static void main(String[] args) {
int[] result = solution(new int[]{1, 2, 3, 4, 5});
for (int num : result) {
System.out.print(num + " ");
}
System.out.println();
result = solution(new int[]{1, 1, 1, 1, 1, 2});
for (int num : result) {
System.out.print(num + " ");
}
System.out.println();
result = solution(new int[]{1, 0, 1, 1, 1, 3, 5});
for (int num : result) {
System.out.print(num + " ");
}
System.out.println();
}
public static int[] solution(int[] num_list) {
List<Integer> list = Arrays.stream(num_list).boxed().collect(Collectors.toList());
Collections.reverse(list);
return list.stream().mapToInt(Integer::intValue).toArray();
}
}
728x90
반응형
'📌Back-End > 프로그래머스' 카테고리의 다른 글
Java 프로그래머스 코딩테스트 입문 Day 7 문자열, 조건문, 수학, 반복문 (0) | 2024.06.28 |
---|---|
Java 프로그래머스 코딩테스트 입문 Day 6 문자열, 반복문, 출력, 배열, 조건문 (0) | 2024.06.27 |
Java 프로그래머스 코딩테스트 입문 Day 4 수학, 배열 (0) | 2024.06.25 |
Java 프로그래머스 코딩테스트 입문 Day 3 사칙연산, 배열, 수학 (0) | 2024.06.24 |
Java 프로그래머스 코딩테스트 입문 Day 2 사칙연산, 조건문, 배열 (0) | 2024.06.23 |