Forums Register Login

Output of code snippet

+Pie Number of slices to send: Send
Can any body tell me why the output of the following code snippet is "ic"

Code Snippet:
String s=new String("Bicycle");
int iBegin=1;
char iEnd=3;
System.out.println(s.substring(iBegin,iEnd));

Why isn't it raising an exception since char is present as second argument
+Pie Number of slices to send: Send
Q1: Can any body tell me why the output of the following code snippet is "ic"

Answer: Because string indexes start at 0

Q2: Why isn't it raising an exception since char is present as second argument

Answer: Because char is a numeric type, and will be interpreted here as an unsigned 16-bit integer
machines help you to do more, but experience less. Experience this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1032 times.
Similar Threads
Marcus Exam #1, Q 26
Important Question From MarcusGreen
String Tokenizer
Doubt in Marcus Test 1
String method
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:23:00.