002-002-012

String Splitting and Formatted Output

Medium

Problem Description

String Splitting and Formatted Output

In this problem: You will create a program that reads multiple lines of strings using Scanner, splits them by delimiters, and displays formatted output to standard output. You will also understand the difference between nextLine() and next().

Learning Objective: Master reading strings containing spaces with Scanner's nextLine() and processing them with split()

Overview

Read a full name and a comma-separated hobby list from standard input, then format and output them.

Input

Line 1: Full name (last and first name separated by space)
Line 2: Comma-separated hobby list

Specifications

  1. Read line 1 and split by space to get last name and first name
  2. Read line 2 and split by comma to get a hobby list
  3. Output in the specified format

Output Format

Last name: Tanaka
First name: Taro
Hobbies:
- Reading
- Gaming
- Cooking

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