013-001-009

Substring Extraction and Concatenation

Medium

Problem Description

Substring Extraction and Concatenation

In this problem, you will create a program that reads a full name from standard input, splits it into last name and first name using the substring() method, concatenates them in reverse order, and displays the result.

Learning Objective: Understand how to extract substrings using the substring() method and how to concatenate strings

Overview

In Java's String class, you can extract a part of a string using the substring() method. You can also concatenate strings using the + operator or the concat() method.

Specifications

  1. Read one line of a full name (e.g., "Yamada Taro") using Scanner
  2. Use the substring() method to extract the last name and first name separately
  3. Concatenate the extracted names in reverse order and output in the format "FirstName LastName"

Hints

  • substring(beginIndex) gets from the specified position to the end of the string
  • substring(beginIndex, endIndex) gets the specified range (endIndex is exclusive)
  • The position of the space can be obtained with indexOf(" ")

Input Format

LastName FirstName

Output Format

FirstName LastName

Example

Input: Yamada Taro
Output: Taro Yamada

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up