Series Program in Loop Program – 1

Series Program in Loop Program – 1

Series Loop program are very useful for high programming. In this blog we will see simple series programs. Next Blog will be hard for us. But we have to focus on these simple programs.

 

Series Loop Program: 1+2+3+….+N = ……

class loop6

{

public static void main(String args[])

{

int i;

int n = Integer.parseInt(args[0]);

int sum=0;

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

{

sum = sum + i;

}

System.out.println(“1+2+….+”+n+”=”+sum);

}

}

Output:

Command line Value is: 10

 1+2+…+10 = 55

 

Series Loop Program: 1-2+3-….+-N = ……

class loop7

{

public static void main(String args[])

{

int i;

int n = Integer.parseInt(args[0]);

int sum=0;

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

{

if(i%2==0)

sum = sum – i;

else

sum = sum + i;

}

if(n%2==0)

System.out.println(“1-2+….-“+n+”=”+sum);

else

System.out.println(“1-2+….+”+n+”=”+sum);

}

}

Output:

Command line Value is: 10

1-2+…-10 = -5

Command line Value is: 9

1-2+-….+9=5

 

List Of Tutorial on Series Program.

NoTitle
1N+….+2+1 = …
2-1+2-3+4- …… +-N =

 

If you have problem on this blog, you can directly comment on it. This tutorial will help you understand the concepts of java loop programs.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

288total visits,1visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

2 Comments

  1. September 9, 2016 - 8:46 pm

    I loved as much aas you’ll receive carried out right here.

    The sketch iss tasteful, your authored subject matter stylish.nonetheless,
    you command get bought aan edginess over that you wish
    be delivering the following. unwell unquestionably come further formerly again since exactly tthe same nearly a
    lot often inside case you shield this hike.

  2. September 9, 2016 - 11:44 pm

    I am sure this paragraph has touched all the internet viewers, its really really pleasant piece of writing on building up new webpage. http://yahoo.org

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

EmailEmail
PrintPrint