aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 18103
    
  39

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: 18103
    
  39

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: 498
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: 36464
    
  15
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
 
Similar Threads
Interview Question: Finding min difference
getting NullPointerException
socket not accepting data 2nd time
Need help for a doubt..Using BufferedReader.
ArrayIndexOutOfBoundsException--- Please help