Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Array, reading input method..

 
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.
 
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.
 
Marshal
Posts: 69399
276
  • 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.
 
Legend has it that if you rub the right tiny ad, a genie comes out.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic