Loop_Practise_Que_09

Home / Java Practice Question / Loop_Practise_Que_09

Loop_Practise_Que_09


Write a Java program to display n terms of natural numbers and their sum.

Program : - 



public class Loop {

    public static int naturalSum(int n){

    int sum=0;
for(int i=1;i<=n;i++){
System.out.println(i);
sum+=i;
}
return sum;
}
}