본문 바로가기

Is One Array a Rotation of Another? (Java) Write a function that returns true if one array is a rotation of another.NOTE: There are no duplicates in each of these arrays. Example: [1, 2, 3, 4, 5, 6, 7] is a rotation of [4, 5, 6, 7, 1, 2, 3]. 풀이 import java.util.List;import java.util.ArrayList;import java.util.Arrays; public class IR { public static void main(String[] args) { // NOTE: The following input values will be used for testing yo.. 더보기
Level 1 - 수박수박수박수박수박수? water_melon함수는 정수 n을 매개변수로 입력받습니다. 길이가 n이고, 수박수박수...와 같은 패턴을 유지하는 문자열을 리턴하도록 함수를 완성하세요.예를들어 n이 4이면 '수박수박'을 리턴하고 3이라면 '수박수'를 리턴하면 됩니다.풀이public class WaterMelon { public String watermelon(int n){ String result = ""; for(int i = 1; i 더보기
Level 1 - 평균구하기 함수를 완성해서 매개변수 array의 평균값을 return하도록 만들어 보세요. 어떠한 크기의 array가 와도 평균값을 구할 수 있어야 합니다. 풀이 public class GetMean { public int getMean(int[] array) { int sum = 0; int length = array.length; for(int i = 0; i 더보기
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 더보기