Advertisement
chiplu

Java first 50 natural number

Nov 17th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. package dadaproject.company;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.       int sum = natural(50);
  8.       System.out.println("The sume is "+sum);
  9.  
  10.  
  11.     }
  12.     public static int natural(int n)
  13.     {
  14.         if(n==1){
  15.             return 1;
  16.         }
  17.         else
  18.         {
  19.             return natural(n-1)+n;
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement