BaşlayınÜcretsiz Başlayın

How long is a String?

Text comes in all sizes - from single characters to entire paragraphs. Knowing how many characters a String contains is essential for validation, formatting, and processing text. Let's discover how Java helps you measure Strings!

Bu egzersiz

Introduction to Java

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Use the .length() method to find out the length of the bookName variable, saving the result as bookNameLength.
  • Find the length of the author's name, "Terry Pratchett", and save it using the correct primitive type.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

class HowLong {
    public static void main(String[] args) {
    
        String bookName = "Good Omens: The Nice and Accurate Prophecies of Agnes Nutter, Witch";
        
        // Find the length of bookName
        int bookNameLength = bookName.____();
        
        // Find the length of the String and save it
        ____ authorNameLength = "Terry Pratchett".____;
        
        System.out.println("The length of the book title is " + bookNameLength);
        System.out.println("The length of the author's name is " + authorNameLength);
    }
}
Kodu Düzenle ve Çalıştır