Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Reference data types (was Ссылочные типы данных)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All good day, please tell me why the Islands are output here, and not the elements of the index array ... After all, in ref index[y].. from the book learning java by Kathy Sierra and Bert Bates
c0oun-kfrEU.jpg
[Thumbnail for c0oun-kfrEU.jpg]
 
Saloon Keeper
Posts: 6197
157
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please edit your post to provide an English language subject (which is the only language allowed here). Also tell us where this material comes from - QuoteYourSources
 
Marshal
Posts: 68066
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please edit the subject of your post to translate it into English, too.
Please follow the value of the ref variable inside the loop near the bottom of the page.
 
Sheriff
Posts: 15038
251
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because of this line:

System.out.println(islands[ref]);

As you iterate through the loop, these are the values of the various expressions:

y  ref = index[y]
0   1
1   3
2   0
3   2

this is why you see the value of islands[1], islands[3], islands[0], and islands[2] printed in that order.
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!