Advertisements
Advertisements
Question
Given that:
String sb = "Satyendra Nath Bose";
String nb = ""+sb.charAt(0)+ sb.charAt(sb.indexOf(' ')+1) + sb.charAt(sb.lastIndexOf(' ')+1);
What will be the value of nb?
Options
SNB
snb
ahe
Sat
MCQ
Advertisements
Solution
SNB
Explanation:
The code extracts the first letter of each word to form initials. It grabs the first letter of the string ('S'), the letter immediately following the first blank space ('N'), and the letter immediately following the last blank space ('B'). Joining them together results in the text SNB.
shaalaa.com
Is there an error in this question or solution?
