• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data Structure Java

 
Ariana Abrenica
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it only prints the last element when it should print the elements that were input.
 
Henry Wong
author
Marshal
Pie
Posts: 21005
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ariana Abrenica
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21005
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you got an array in that code in the first place?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic