javaprograms

Ads
 

javaprograms

write series code

3,8,15,24...............n terms

View Answers

September 9, 2011 at 3:13 PM

import java.util.*;

class NumberExample 
{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter value of n: ");
        int n=input.nextInt();
        int sum=0;
        int m=0;
        for(int i=2;i<=n;i++){
             m=(i-1)*(i+1);
             sum+=m;
            System.out.print(m+" ");
        }
        System.out.println();
        System.out.println("Sum of series: "+sum);
    }
}

Ads









Related Tutorials/Questions & Answers:
javaprograms
javaprograms
Advertisements
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms

Ads