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.

647total visits,2visits today


mayank

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

Related articles

2 responses to “Series Program in Loop Program – 1”

  1. 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.