Sunday, August 18, 2019

BlueJ Program To Display Sum of The Series s=1+(1+2+3)+ (1+2+3+4+5)+... n terms


BlueJ Program on sum of series like 1+(1+2+3)+ (1+2+3+4+5)+... n terms.



import java.util.*;
public class Series1
{
    Scanner sc=new Scanner(System.in);
    int s=0,n,i,j;

    public void secondSeries()
    {
          System.out.print("\nEnter the value of 'n':");
         n=sc.nextInt();
         s=0;
         for(i=1;i<=n;i=i+2)
         {
              for(j=1;j<=i;j++)
              {
                   s=s+j;
                }
            }
            System.out.print("Sum of the series 1+(1+2+3)+ (1+2+3+4+5)+... n terms.... n term:"+s);
            }
                  
            public static void main(String args[])


            {
                 Series1 obj=new Series1 ();
                 obj.secondSeries();
              }
            }


Related Post: BlueJ Programs on Series

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner