Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array iteration/output problem  RSS feed

 
Shio Nakashima
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have to write a for loop, to iterate through an array and output the contents of the array (see below). I know how to write the code for the iteration but am having a problem with the output.

The output should go

mortgageType [1] = array contents.
mortgageType [2] = array contents.

I can get the array index to print out ( but cannot get the others to print on the same line. Any ideas?

Also, I have one loop and am wondering should I have 2?

Any help gratefully received.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want to do this ?

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Helen Back:
...The output should go

mortgageType [1] = array contents.
mortgageType [2] = array contents.
...

Note that array indexing starts at zero. So, for example, if your array has 3 elements, these would be indexed as...

mortgageType[0]
mortgageType[1]
mortgageType[2]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Helen --

Please contact me by email (click the little icon of a speedy stamped envelope at the top of this post.) Thank you.
 
Shio Nakashima
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all, just the starting point I needed, I can probably figure it out now.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!