013-001-008
Getting String Length
Easy
Problem Description
Getting String Length
In this problem, you will create a program that calls the length() method on a String variable 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
- Declare a String variable
messageand initialize it with "Hello, Java!" - Use the
length()method to get the length of the string - Output the result in the specified format
Output Format
Length: 12
Test Cases
※ Output examples follow programming industry standards
Input:
Expected Output:
Length: 12
Input:
Expected Output:
Length: 12
Input:
Expected Output:
Length: 12
Input:
Expected Output:
Length: 12
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here
sc.close();
}
}
0 B / 5 MB
You have 7 free executions remaining
