| Author |
Data Structure Java
|
Ariana Abrenica
Greenhorn
Joined: Jan 06, 2012
Posts: 12
|
|
it only prints the last element when it should print the elements that were input.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
Ariana Abrenica wrote:it only prints the last element when it should print the elements that were input.
Hint: what is the code doing at line 13?
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Ariana Abrenica
Greenhorn
Joined: Jan 06, 2012
Posts: 12
|
|
Henry Wong wrote:
Ariana Abrenica wrote:it only prints the last element when it should print the elements that were input.
Hint: what is the code doing at line 13?
Henry
it prints the array but when I removed [Size-1] -1 I'm having outofboundsexception
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
Ariana Abrenica wrote:it prints the array but when I removed [Size-1] -1 I'm having outofboundsexception
You might want to review arrays -- and how do they work.... what that line does is print the last element.
Henry
|
 |
Saurabh Pillai
Ranch Hand
Joined: Sep 12, 2008
Posts: 449
|
|
Ariana Abrenica wrote:it only prints the last element when it should print the elements that were input.
- You do realize that is outside of for loop. Indentation is crucial to quickly uncover this type of problems.
- Considering that please explain, what do YOU think this line should print? Replace size with some number for example, 5.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
|
Why have you got an array in that code in the first place?
|
 |
 |
|
|
subject: Data Structure Java
|
|
|