013-001-008

Getting String Length

Easy

Problem Description

Getting String Length

In this problem, you will create a program that reads a string from standard input, calls the length() method to obtain the number of characters, and displays the result to standard output.

Learning Objective: Understand how to get the length of a string using the length() method of the String class

Overview

When working with strings in Java, knowing their length (number of characters) is a fundamental operation. The String class provides the length() method to get the length of a string.

Specifications

  1. Use Scanner to read one line of text from standard input
  2. Use the length() method to get the length of the string
  3. Output the result in the specified format

Input

a string (one line)

Output Format

Length: <character count>

Sample I/O

Input: Hello, Java!
Output: Length: 12

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