String कितनी लंबी है?
टेक्स्ट कई आकारों में आता है — एकल कैरेक्टर से लेकर पूरे पैराग्राफ तक. किसी String में कितने कैरेक्टर हैं, यह जानना वैलिडेशन, फ़ॉर्मेटिंग, और टेक्स्ट प्रोसेसिंग के लिए ज़रूरी है. आइए देखें कि Java Strings को मापने में आपकी कैसे मदद करता है!
यह अभ्यास पाठ्यक्रम का हिस्सा है
Java परिचय
अभ्यास निर्देश
.length()मेथड का उपयोग करकेbookNameवैरिएबल की लंबाई पता करें और परिणामbookNameLengthके रूप में सेव करें.- लेखक के नाम
"Terry Pratchett"की लंबाई निकालें और उसे सही प्रिमिटिव टाइप में सेव करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
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);
}
}