netoops blog

Friday, 20 September 2013

Print Series 2 -4 6 -8………n terms

import  java.util.Scanner;
public class EvenSeries
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        int c,i=2,n; // c for counter, i for even nos.
        System.out.print(“Enter the number of terms: “);
        n=sc.nextInt();
        System.out.print(“\n”);
        for(c=1; c<=n; c++, i+=2)//to generate n terms of the series
        {
            if(i%4==0)
                System.out.print(-i+”  ”);
            else
                System.out.print(i+”   “);
        }//method ends
    }
}//class ends

Tech Knowledege
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments :

Post a Comment

 
Subscribe For Free Updates!

We'll not spam mate! We promise.

Become Our Fan on Social Sites!