Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. public class Factorial {
  2. int sum(int n)
  3. {
  4. int sm=0;
  5. if(n==1)
  6. return 1;
  7. System.out.println("sm"+sm+"n"+n);
  8. sm=n+sum(n-1);
  9. System.out.println("sm"+sm);
  10. return sm;
  11. }
  12. public static void main(String[] args){
  13. int n,s;
  14. System.out.println("Enter the limit:");
  15. n=3;
  16. s=new Factorial().sum(n);
  17. System.out.println("Sum of natural numbers %d"+s);
  18. //return 0;
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement