aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Jq + Question ID : 953841239150 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Jq + Question ID : 953841239150" Watch "Jq + Question ID : 953841239150" New topic
Author

Jq + Question ID : 953841239150

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
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

Joined: Aug 26, 2000
Posts: 1242
Yeah.. agree, it is "ing "
what were the list of answer to pick from?
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3324
    
    8
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


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
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

Joined: Dec 28, 2001
Posts: 26
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


Suraj Berwal
Sun Certified Programmer for Java 2 Platform
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
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

Joined: Aug 26, 2000
Posts: 1242
oops..
Everyone is right.
No space! so it is D) none of the above.

 
Consider Paul's rocket mass heater.
 
subject: Jq + Question ID : 953841239150