blog.itcode.devblog.itcode.dev

[Programmers / JAVA] Level 1 Finding Mr. Kim in Seoul (12919)

Find the position x of "Kim" among the elements of the String array seoul, and complete the solution function that returns a String saying "Mr. Kim is at x". "Kim" appears only once in seoul, and there will be no invalid input.

[Programmers / JAVA] Level 1 Finding Mr. Kim in Seoul (12919)

Find the position x of "Kim" among the elements of the String array seoul, and complete the solution function that returns a String saying "Mr. Kim is at x". "Kim" appears only once in seoul, and there will be no invalid input.
RWB0104
@RWBwritten at 2021-12-17 09:33:21
Programmers

시리즈 모아보기

Programmers

44 / 78
RankLanguage Used
Level 1

🖼️ JAVA

🔗 Finding Mr. Kim in Seoul

Find the position x of "Kim" among the elements of the String array seoul, and complete the solution function that returns a String saying "Mr. Kim is at x". "Kim" appears only once in seoul, and there will be no invalid input.

  • seoul is an array of length 1 to 1000, inclusive.
  • The elements of seoul are strings of length 1 to 20, inclusive.
  • "Kim" is guaranteed to be included in seoul.
seoulreturn
{ "Jane", "Kim" }"Mr. Kim is at 1"

Unlike a plain array like String[], a List provides a method called indexOf() that returns the position of the desired element.

Use the Arrays.asList() method to convert the array into a List, then use indexOf() to get the position and use it to build and return the answer.

JAVA

import java.util.Arrays;

/**
 * Finding Mr. Kim in Seoul class
 *
 * @author RWB
 * @since 2021.12.13 Mon 15:44:33
 */
class Solution
{
	/**
	 * Method that returns the answer
	 *
	 * @param seoul: [String[]] strings
	 *
	 * @return [String] the answer
	 */
	public String solution(String[] seoul)
	{
		return new StringBuilder("김서방은 ").append(Arrays.asList(seoul).indexOf("Kim")).append("에 있다").toString();
	}
}
# Programmers# Algorithm# JAVA# Level 1
ship
blog.itcode.dev

Notes from the π-th Alpaca

7.0.1
Developed by RWB since 2021.057th upgraded at 2026.08