본문 바로가기

Level 1 - 서울에서김서방찾기 findKim 함수(메소드)는 String형 배열 seoul을 매개변수로 받습니다.seoul의 element중 Kim의 위치 x를 찾아, 김서방은 x에 있다는 String을 반환하세요. seoul에 Kim은 오직 한 번만 나타나며 잘못된 값이 입력되는 경우는 없습니다.풀이public class FindKim { public String findKim(String[] seoul){ //x에 김서방의 위치를 저장하세요. int x = 0; for(int i = 0; i 더보기
Level 1 - 스트링을 숫자로 바꾸기 strToInt 메소드는 String형 str을 매개변수로 받습니다. str을 숫자로 변환한 결과를 반환하도록 strToInt를 완성하세요. 예를들어 str이 1234이면 1234를 반환하고, -1234이면 -1234를 반환하면 됩니다. str은 부호(+,-)와 숫자로만 구성되어 있고, 잘못된 값이 입력되는 경우는 없습니다. 풀이 public class StrToInt { public int getStrToInt(String str) { return Integer.parseInt(str); } //아래는 테스트로 출력해 보기 위한 코드입니다. public static void main(String args[]) { StrToInt strToInt = new StrToInt(); System.out.pri.. 더보기
Common Elements in Two Sorted Arrays (Java) Write a function that returns the common elements (as an array) between two sorted arrays of integers (ascending order).Example: The common elements between [1, 3, 4, 6, 7, 9] and [1, 2, 4, 5, 9, 10] are [1, 4, 9]. 풀이 import java.util.ArrayList;import java.util.HashMap;import java.util.List; public class CE { public static void main(String[] args) { // NOTE: The following input values are used f.. 더보기
Day 5: Loops Task Given an integer, , print its first multiples. Each multiple (where ) should be printed on a new line in the form: n x i = result.Input FormatA single integer, .ConstraintsOutput FormatPrint lines of output; each line (where ) contains the of in the form: n x i = result.Sample Input2 Sample Output2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 .. 더보기
Day 4: Class vs. Instance Task Write a Person class with an instance variable, , and a constructor that takes an integer, , as a parameter. The constructor must assign to after confirming the argument passed as is not negative; if a negative argument is passed as , the constructor should set to and print Age is not valid, setting age to 0.. In addition, you must write the following instance methods:yearPasses() should in.. 더보기
Level 1- 짝수와 홀수 evenOrOdd 메소드는 int형 num을 매개변수로 받습니다. num이 짝수일 경우 Even을 반환하고 홀수인 경우 Odd를 반환하도록 evenOrOdd에 코드를 작성해 보세요. num은 0이상의 정수이며, num이 음수인 경우는 없습니다. 풀이 public class EvenOrOdd { String evenOrOdd(int num) { String result = ""; if (num % 2 == 0){ result = "Even"; } else { result = "Odd"; } return result; } public static void main(String[] args) { String str = "1 2 3 4"; EvenOrOdd evenOrOdd = new EvenOrOdd(); /.. 더보기
Level 1 - 삼각형출력하기 printTriangle 메소드는 양의 정수 num을 매개변수로 입력받습니다. 다음을 참고해 *(별)로 높이가 num인 삼각형을 문자열로 리턴하는 printTriangle 메소드를 완성하세요 printTriangle이 return하는 String은 개행문자('\n')로 끝나야 합니다.높이가 3일때* ** *** 높이가 5일때* ** *** **** ***** 풀이 public class PrintTriangle {public String printTriangle(int num){ String str =""; for(int i =1; i 더보기
Day 3: Intro to Conditional Statements Task Given an integer, , perform the following conditional actions:If is odd, print WeirdIf is even and in the inclusive range of to , print Not WeirdIf is even and in the inclusive range of to , print WeirdIf is even and greater than , print Not WeirdComplete the stub code provided in your editor to print whether or not is weird.Input FormatA single line containing a positive integer, .Constrai.. 더보기
Day 2: Operators Task Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost.Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result!Input FormatThere are lines of numeric input: The f.. 더보기
Hash Tables: Ransom Note A kidnapper wrote a ransom note but is worried it will be traced back to him. He found a magazine and wants to know if he can cut out whole words from it and use them to create an untraceable replica of his ransom note. The words in his note are case-sensitive and he must use whole words available in the magazine, meaning he cannotuse substrings or concatenation to create the words he needs.Give.. 더보기