fork download
  1. import java.util.*;
  2.  
  3. class Iterations
  4. {
  5. public static void main(String[] args)
  6. {
  7. new Iterations();
  8. }
  9. public Iterations()
  10. {
  11. Random r = new Random();
  12. int howMany = r.nextInt(3)+3;
  13. ArrayList<Integer> iterations = new ArrayList<Integer>();
  14. for(int i=0;i<howMany;i++)
  15. {
  16. iterations.add(r.nextInt(5)+3);
  17. }
  18. allSums(iterations,new ArrayList<Integer>());
  19. }
  20. private void allSums(ArrayList<Integer> iterations, ArrayList<Integer> indexes)
  21. {
  22. if(iterations.size() == 1)
  23. {
  24. for(int i=0;i<iterations.get(0);i++)
  25. {
  26. int sum = i;
  27. String txt = ""+i;
  28. for(int l:indexes)
  29. {
  30. sum+=l;
  31. txt+="+"+l;
  32. }
  33. System.out.println(txt+"="+sum);
  34. }
  35. }
  36. else
  37. {
  38. for(int i=0;i<iterations.get(0);i++)
  39. {
  40. ArrayList<Integer> iters = new ArrayList<Integer>();
  41. iters.addAll(iterations);
  42. iters.remove(0);
  43. ArrayList<Integer> indexes2 = new ArrayList<Integer>(indexes);
  44. indexes2.add(i);
  45. allSums(iters,indexes2);
  46. }
  47. }
  48. }
  49. }
Success #stdin #stdout 0.08s 380480KB
stdin
Standard input is empty
stdout
0+0+0=0
1+0+0=1
2+0+0=2
3+0+0=3
4+0+0=4
0+0+1=1
1+0+1=2
2+0+1=3
3+0+1=4
4+0+1=5
0+0+2=2
1+0+2=3
2+0+2=4
3+0+2=5
4+0+2=6
0+0+3=3
1+0+3=4
2+0+3=5
3+0+3=6
4+0+3=7
0+0+4=4
1+0+4=5
2+0+4=6
3+0+4=7
4+0+4=8
0+0+5=5
1+0+5=6
2+0+5=7
3+0+5=8
4+0+5=9
0+1+0=1
1+1+0=2
2+1+0=3
3+1+0=4
4+1+0=5
0+1+1=2
1+1+1=3
2+1+1=4
3+1+1=5
4+1+1=6
0+1+2=3
1+1+2=4
2+1+2=5
3+1+2=6
4+1+2=7
0+1+3=4
1+1+3=5
2+1+3=6
3+1+3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