728x90
반응형
출력
/**
* 코딩테스트 연습 PCCE 기출문제 1번
* 출력
*/
public class Main0722_1 {
public static void main(String[] args) {
String msg = "Spring is beginning";
int val1 = 3;
String val2 = "3";
System.out.println(msg);
System.out.println(val1 + 10);
System.out.println(val2 + "10");
}
}
피타고라스의 정리
import java.util.Scanner;
/**
* 코딩테스트 연습 PCCE 기출문제 2번
* 피타고라스의 정리
*/
public class Main0722_2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int c = sc.nextInt();
int b_square = (int) Math.pow(c, 2) - (int) Math.pow(a, 2);
System.out.println(b_square);
}
}
나이 계산
import java.util.Scanner;
/**
* 코딩테스트 연습 PCCE 기출문제 3번
* 나이 계산
*/
public class Main0722_3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
String age_type = sc.next();
int answer = 0;
if (age_type.equals("Korea")) {
answer = 2030 - year + 1;
} else if (age_type.equals("Year")) {
answer = 2030 - year;
}
System.out.println(answer);
}
}
저축
import java.util.Scanner;
/**
* 코딩테스트 연습 PCCE 기출문제 4번
* 저축
*/
public class Main0722_4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int start = sc.nextInt();
int before = sc.nextInt();
int after = sc.nextInt();
int money = start;
int month = 1;
while (money < 70) {
money += before;
month++;
}
while (money < 100) {
money += after;
month++;
}
System.out.println(month);
}
}
산책
/**
* 코딩테스트 연습 PCCE 기출문제 5번
* 산책
*/
public class Main0722_5 {
public static void main(String[] args) {
int[] result = solution("NSSNEWWN");
for (int num : result) {
System.out.print(num + " ");
}
System.out.println();
result = solution("EESEEWNWSNWWNS");
for (int num : result) {
System.out.print(num + " ");
}
System.out.println();
}
public static int[] solution(String route) {
int east = 0;
int north = 0;
int[] answer = new int[2];
for (int i = 0; i < route.length(); i++) {
switch (route.charAt(i)) {
case 'N':
north++;
break;
case 'S':
north--;
break;
case 'E':
east++;
break;
case 'W':
east--;
break;
}
}
answer[0] = east;
answer[1] = north;
return answer;
}
}
728x90
반응형
'📌Back-End > 프로그래머스' 카테고리의 다른 글
Java 프로그래머스 코딩테스트 입문 Day 25 시뮬레이션, 조건문, 수학 (0) | 2024.07.19 |
---|---|
Java 프로그래머스 코딩테스트 입문 Day 24 수학, 시뮬레이션, 문자열, 조건문, 반복문 (0) | 2024.07.18 |
Java 프로그래머스 코딩테스트 입문 Day 23 배열, 정렬, 문자열 (0) | 2024.07.17 |
Java 프로그래머스 코딩테스트 입문 Day 22 dp, 수학, 조건문, 배열 (0) | 2024.07.16 |
Java 프로그래머스 코딩테스트 입문 Day 21 문자열, 사칙연산, 시뮬레이션, 2차원배열, 수학, 배열 (2) | 2024.07.15 |