Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Factorial {
- int sum(int n)
- {
- int sm=0;
- if(n==1)
- return 1;
- System.out.println("sm"+sm+"n"+n);
- sm=n+sum(n-1);
- System.out.println("sm"+sm);
- return sm;
- }
- public static void main(String[] args){
- int n,s;
- System.out.println("Enter the limit:");
- n=3;
- s=new Factorial().sum(n);
- System.out.println("Sum of natural numbers %d"+s);
- //return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement