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
Average Rating