Java Programming - Java.lang Class - Discussion
Discussion Forum : Java.lang Class - Finding the output (Q.No. 19)
19.
What will be the output of the program?
String a = "newspaper";
a = a.substring(5,7);
char b = a.charAt(1);
a = a + b;
System.out.println(a);
Answer: Option
Explanation:
Both substring() and charAt() methods are indexed with a zero-base, and substring() returns a String of length arg2 - arg1.
Discussion:
15 comments Page 2 of 2.
Vinod said:
1 decade ago
In obj a now "ape".
a.charAt(0) means "a".
a.charAt(1) means "p".
a.charAt(0) means "a".
a.charAt(1) means "p".
Srinu said:
8 years ago
Length start from 0 now (sunstring(5,7) return ape)
charAt(1) retuns=p then,
Final the output.
charAt(1) retuns=p then,
Final the output.
Sai said:
10 years ago
a.substring (5,7-1).
a.substring (5,6) will return ap.
And a.charAt (1).
Result is app//
a.substring (5,6) will return ap.
And a.charAt (1).
Result is app//
Aaa said:
1 decade ago
7-5 = 2 means length is 2.
a = ap.
a.charAt(1) = p.
a = ap.
a.charAt(1) = p.
Ahmed said:
1 decade ago
How a.charAt(1) returns "p"?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers