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. // recusrion
  11. public static void rec(int n){
  12. if(n>0){
  13. rec(n-1);
  14. System.out.print(n+" ");
  15. }
  16. }
  17. public static void main (String[] args) throws java.lang.Exception
  18. {
  19. Scanner sc=new Scanner(System.in);
  20. int n=sc.nextInt();
  21. System.out.print("recursion \n");
  22. rec(n);
  23. System.out.print("\nLoop \n");
  24. for(int i=1;i<=n;i++){
  25. System.out.print(i+" ");
  26. }
  27. }
  28. }
Success #stdin #stdout 0.15s 56968KB
stdin
5
stdout
recursion 
1 2 3 4 5 
Loop 
1 2 3 4 5