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. // your code goes here
  13. foo(5, 5);
  14. }
  15.  
  16. public static void foo(int num, int th) {
  17. if (num == 0) {
  18. System.out.print(num + " ");
  19. return;
  20. }
  21. if ( num == 1) {
  22. System.out.print(th + " ");
  23. System.out.print((th - num) + " ");
  24. return;
  25. }
  26. System.out.print(( th - num) + " ");
  27. foo(num - 1, th);
  28.  
  29. System.out.print((th - num) + " ");
  30. }
  31.  
  32. }
Success #stdin #stdout 0.1s 33968KB
stdin
Standard input is empty
stdout
0 1 2 3 5 4 3 2 1 0