File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jq + Question ID : 953841239150

 
sonir shah
Ranch Hand
Posts: 435
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the output of the following program (excluding the quotes, of course)?
public class SubstringTest
{
public static void main(String args[])
{
String String = "string isa string";
System.out.println(String.substring(3, 6));
}
}
Ans : e) None of the above.
But , the answer should be d) "ing "(There is a space after g)
 
Fei Ng
Ranch Hand
Posts: 1244
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah.. agree, it is "ing "
what were the list of answer to pick from?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3669
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer given the question is correct. It prints "ing" (no space after g) and not "ing ".
------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD
 
sonir shah
Ranch Hand
Posts: 435
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the option were as follows:
1) It will not compile
2)"ing is"
3)"ing isa"
4)"ing "(There is a space after g)
5) None of the above.
According to me the answer is 4.
But jq+ plus says the answer is 5
Please Explain
 
Suraj Berwal
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sonir shah:
the option were as follows:
1) It will not compile
2)"ing is"
3)"ing isa"
4)"ing "(There is a space after g)
5) None of the above.
According to me the answer is 4.
But jq+ plus says the answer is 5
Please Explain

dear sonir,
HAPPY NEW YEAR!!!
the substring(int inedx, int offset) function only evaluates the string to the value offset-1. hence when u specified String.substring(3,6) it copied the characters from the 3rd positon(starting from 0) to (6-1)=5th postion.hence only ing was printed. please consult any textbook for more details or JLS.
regards,
Suraj
 
Ragu Sivaraman
Ranch Hand
Posts: 464
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sonir shah:
the option were as follows:
1) It will not compile
2)"ing is"
3)"ing isa"
4)"ing "(There is a space after g)
5) None of the above.
According to me the answer is 4.
But jq+ plus says the answer is 5
Please Explain

Yes you are correct , the answer is ing
So the answer choice is (5)
(4) not valid why becoz it has a space
substring(intialindex, endindex)
gives out a string from intialindex to endindex-1
Hope it helps
Ragu
 
Fei Ng
Ranch Hand
Posts: 1244
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops..
Everyone is right.
No space! so it is D) none of the above.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic