Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


k.jahangir kumar
javaprograms
1 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


write series code

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


Advertisement
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);
    }
}


Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com