Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 Java 8 in Action this week in the Java 8 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: 3970
    
  17



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
 
Similar Threads
can anyone tell me how many joins are in SQL.AND how many are in Oracle.?
Need help in java some implemting logic
Assignment Java-5 (Times)
Quit audio before application exits.
Excelsheet content reading