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 solve(String acc, int n, int last)
  11. {
  12. if (n == 0) System.out.println(acc);
  13. for (int i = 1; i <= n; i++)
  14. {
  15. solve(acc + "+" + i, n - i, i);
  16. }
  17. }
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. // your code goes here
  21. int n = 4;
  22. for (int i = 1; i < n; i++)
  23. solve(Integer.toString(i), n - i, i);
  24. }
  25. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
1+1+1+1
1+1+2
1+2+1
1+3
2+1+1
2+2
3+1