jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Data Structure Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Data Structure Java" Watch "Data Structure Java" New topic
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: 18914
    
  40

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: 18914
    
  40

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: 509
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: 39478
    
  28
Why have you got an array in that code in the first place?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data Structure Java