How to find the length of the string?

0 0
Read Time:33 Second

Write a program to find the length of the string “refrigerator”.

public class StringLengthExample {
  public static void main(String[] args) {
    String word = "refrigerator";
    int length = word.length();
    System.out.println("The length of the word " + word + " is " + length);
  }
}

In this program, we first declare a String variable word and assign it the value “refrigerator”. Then, we use the length() method of the String class to find the length of the string and store it in an int variable length. Finally, we print out the result using the println() method of the System.out object.

When you run this program, it should output:

The length of the word refrigerator is 12
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Comment