본문 바로가기

전체 글

(138)
배열의 평균값 /* 배열의 평균값 * 정수 배열 numbers가 매개변수로 주어집니다. * numbers의 원소의 평균값을 return * * numbers result * [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 5.5 * [89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] 94.0 */ 12345678910111213141516171819public class programmer_0_42 { static int[] a1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; static int[] a2 = {89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99}; public double solution(int[] numbers) { dou..
나이출력 /* 나이출력 * 나이 age가 주어질 때, 2022년을 기준 출생 연도를 return * * age result * 40 1983 * 23 2000 */ 1234567891011121314151617public class programmer_0_43 { static int a1 = 40; static int a2 = 23; public int solution(int age) { int answer = 0; return 2022 - (age - 1); } public static void main(String args[]){ programmer_0_43 t = new programmer_0_43(); System.out.println("--------------------------------------..
각도기 /* 각도기 * 각에서 0도 초과 90도 미만은 예각, 90도는 직각, * 90도 초과 180도 미만은 둔각 180도는 평각으로 분류. * 각 angle이 매개변수로 주어질 때 * 예각일 때 1, 직각일 때 2, 둔각일 때 3, 평각일 때 4를 return * * angle result * 70 1 * 91 3 * 180 4 */ 1234567891011121314151617181920212223242526public class programmer_0_44 { static int a1 = 70; static int a2 = 91; static int a3 = 180; public int solution(int angle) { int answer = 0; if(angle > 0 && angle 90 && ..
짝수의 합 /* 짝수의 합 * 정수 n이 주어질 때, n이하의 짝수를 모두 더한 값을 return * * n result * 10 30 * 4 6 */ 12345678910111213141516171819202122public class programmer_0_45 { static int a1 = 10; static int a2 = 4; public int solution(int n) { int answer = 0; for(int i = 1; i
양꼬치 /* 양꼬치 * 양꼬치 가게는 10인분을 먹으면 음료수 하나를 서비스로 줍니다. * 양꼬치는 1인분에 12,000원, 음료수는 2,000원입니다. * 정수 n과 k가 매개변수로 주어졌을 때, * 양꼬치 n인분과 음료수 k개를 먹었다면 총얼마를 지불해야 하는지 return * * n k result * 10 3 124,000 * 64 6 768,000 */ 1234567891011121314151617181920public class programmer_0_46 { static int a1 = 10; static int b1 = 3; static int a2 = 64; static int b2 = 6; public int solution(int n, int k) { int answer = 0; if(n /..
머쓱이보다 키 큰 사람 /* 머쓱이보다 키 큰 사람 * 반 친구들의 키가 담긴 정수 배열 array와 * 머쓱이의 키 height가 매개변수로 주어질 때, * 머쓱이보다 키 큰 사람 수를 return * * array height result * [149, 180, 192, 170] 167 3 * [180, 120, 140] 190 0 */ 12345678910111213141516171819public class programmer_0_47 { static int[] a1 = {149, 180, 192, 170}; static int b1 = 167; static int[] a2 = {180, 120, 140}; static int b2 = 190; public int solution(int[] array, int heigh..
중복된 숫자의 개수 /* 중복된 숫자의 개수 * 정수가 담긴 배열 array와 정수 n이 매개변수로 주어질 때, * array에 n이 몇 개 있는 지를 return * * array n result * [1, 1, 2, 3, 4, 5] 1 2 * [0, 2, 3, 4] 1 0 */ 12345678910111213141516171819public class programmer_0_48 { static int[] a1 = {1, 1, 2, 3, 4, 5}; static int b1 = 1; static int[] a2 = {0, 2, 3, 4}; static int b2 = 1; public int solution(int[] array, int n) { int answer = 0; for(int i : array){ if(n ..
옷가게 할인받기 /* 옷가게 할인받기 * 옷가게는 10만 원 이상 사면 5%, * 30만 원 이상 사면 10%, * 50만 원 이상 사면 20%를 할인해줍니다. * 구매한 옷의 가격 price가 주어질 때, 지불해야 할 금액을 return * * price result * 150,000 142,500 * 580,000 464,000 */ 1234567891011121314151617181920public class programmer_0_49 { static int a1 = 150000; static int a2 = 580000; public int solution(int price) { int answer = 0; if(price >= 100000 && price = 300000 && price = 500000) an..