Correct option is A
The correct output of the code is
"The length of the string 'Hello, World!' is: 13".
· The method customStringLength() iterates through each character of the string using a for-each loop and increments a counter (length) for every character.
· The input string "Hello, World!" has 13 characters, including the comma , and the space between Hello and World.
· The if (str == null) condition ensures the method throws an exception if the input string is null.
Important Key Points:
1.
Manual String Length Calculation: The method counts characters using a loop, avoiding the built-in length() method.
2.
Handling Null Input: The method validates the input string and throws an exception for null values, preventing runtime errors.
3.
String Details: "Hello, World!" includes 13 characters: