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. Scanner sc = new Scanner(System.in);
  14. int n = sc.nextInt();
  15. int res = fun(n);
  16. System.out.println(res);
  17.  
  18. }
  19.  
  20. public static int fun(int n){
  21. if(n==0)
  22. return 0; // now the process start of sending answer upward.
  23. return n + fun(n-1);
  24. }
  25. }
Success #stdin #stdout 0.16s 54592KB
stdin
10
stdout
55