Computer Science, asked by secret463, 1 year ago

S=1+(1+2)+(1+2+3)+.....+(1+2+3+........+n)


Anonymous: shud I print the series using JAVA?

Answers

Answered by Anonymous
4

Here is the code of the program

_____________________________________

Code


import java.util.*;


class series_sum


{


   public void main()


   {


       Scanner sc=new Scanner(System.in);


       System.out.println("Enter the value of the last term");


       int n=sc.nextInt();


       int s=0;


       int sum;


       for(int i=1;i<=n;i++)


       {


           sum=0;


           for(int j=1;j<=i;j++)


           {


               sum=sum+j;


           }


           s=s+sum;


       }


       System.out.println("Sum="+s);


   }


}


___________________________________________________

Sample input :

2

Output :

4

Working

S=1+1+2

  = 2+2

  =4

Hence output is 4.

______________________________________________________


Hope it helps you

_____________________________________________________________________



secret463: Thank you sir
Anonymous: welcome! but I am a student not a sir!
Similar questions