본문 바로가기

Level 1 - 가운데 글자 가져오기 getMiddle메소드는 하나의 단어를 입력 받습니다. 단어를 입력 받아서 가운데 글자를 반환하도록 getMiddle메소드를 만들어 보세요. 단어의 길이가 짝수일경우 가운데 두글자를 반환하면 됩니다. 예를들어 입력받은 단어가 power이라면 w를 반환하면 되고, 입력받은 단어가 test라면 es를 반환하면 됩니다. 풀이 class StringExercise{ String getMiddle(String word){ String result = ""; int middle = (word.length() / 2); if (word.length() % 2 == 0) { middle = (word.length() / 2); result += String.valueOf(word.charAt(middle - 1)); .. 더보기
Non-Repeating Character (Java) Implement a function that takes a string and returns the first character that does not appear twice or more.Example:"abacc" -> 'b' ('a' appears twice, and so does 'c')"xxyzx" -> 'y' ('y' and 'z' are non-repeating characters, and 'y' appears first)If there is no non-repeating character, return null. 풀이 import java.util.*; public class NR { public static void main(String[] args) { // NOTE: The fol.. 더보기
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.. 더보기