| Author |
How does this method work?
|
Olivier Legat
Ranch Hand
Joined: Nov 17, 2007
Posts: 176
|
|
The output is "his_". What is the variable buf[] for? My teacher told me to put it but I don't know why! Another thing I don't understand is why does it stop at the first "_"? Shouldn't it display "his_i"? (i.e. Up until index 5 since int end=5)
|
Olly
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
Originally posted by Olivier Legat: What is the variable buf[] for? My teacher told me to put it but I don't know why!
The variable "buf" with the pair of square brackets "[]" means an array! A set of contiguous memory locations being used to store the similar kinda data value. Here in this case, you use a container to store a set of characters. so you need an array of characters. In Java, you declare the array in this way!
Another thing I don't understand is why does it stop at the first "_"? Shouldn't it display "his_i"? (i.e. Up until index 5 since int end=5)
Well, end is 5 and start is 1. so, (end-start) will give you 4 (5-1=4 ). As the arrays always start with 0 instead of 1, you will get upto 4. Does that help?
|
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
Also, in nearly all API calls that need an end index, this end index is exclusive. So if you want characters 1 to 5, you need to give the end as 6.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Olivier Legat
Ranch Hand
Joined: Nov 17, 2007
Posts: 176
|
|
|
YAH! Helps loadz. Thanks
|
 |
 |
|
|
subject: How does this method work?
|
|
|