Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nested loops

 
Gerald Nah Haw Yuan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using nested loops, how do i print the following output :
1
12
123
1234
12345
from an array like int[] a={1,2,3,4,5};
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it a homework?

HTH

[ August 08, 2003: Message edited by: siu chung man ]
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought this question was answered, but while both examples provide the intended output, they obviously don't provide the intended functionality. The first example is completely dependent upon the contents of the array being what it is because j is compared to the value contained by the array rather than the index, if you change the contents it will give you an error. I very much doubt that's what was intended. The second one doesn't even use an array, and question specifically said it was to be done from an array.
I believe the solution you are seeking would be more along the lines of...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic