fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] loops = {5, 4, 6};
  13. String[] names = {"first", "second", "third"};
  14.  
  15. for (int i = 0, sum = 0; i < loops.length; sum += loops[i++])
  16. for(int j = sum; j < sum + loops[i]; j++)
  17. System.out.println((j + 1) + " The " + names[i] + " loop");
  18. }
  19. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
1 The first loop
2 The first loop
3 The first loop
4 The first loop
5 The first loop
6 The second loop
7 The second loop
8 The second loop
9 The second loop
10 The third loop
11 The third loop
12 The third loop
13 The third loop
14 The third loop
15 The third loop