aspose file tools*
The moose likes Beginning Java and the fly likes nested loops Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "nested loops" Watch "nested loops" New topic
Author

nested loops

Gerald Nah Haw Yuan
Greenhorn

Joined: Aug 07, 2003
Posts: 7
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

Joined: Jan 04, 2003
Posts: 867
Is it a homework?

HTH

[ August 08, 2003: Message edited by: siu chung man ]

Francis Siu
SCJP, MCDBA
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21



Steve
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nested loops