• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array, reading input method..  RSS feed

 
S. Freeman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Input: 1 2 3 4
Output: [1, 2]

To me it seems that the if statement is not accessed, and of course i do not know why. Can someone tell me why is that? Or even better if i missed something, point me in the right direction because i don't see why the length of my array stays the same.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read this article on pass-by-value vs. pass-by-reference you should be able to figure out what the dealio is.
 
S. Freeman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
I thought that they only point to the same array, and that by modifying the array the references would "update" themselves.
Gotta blame my imagination a bit for this, because i always thought of arrays as trains, with locomotive being the reference
and pulling the wagons no matter how many there are. Did not know that i needed to tell the locomotive how many too pull.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never close a scanner pointing to System.inSee what happens

You could argue that you should have one Scanner and one only pointing to System.in and I would agree.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!