Series 2

Series 2


Write a program to print the following series: 1,8,27,64,125..........u pto n terms.

/* The given series can be generated by calculating
the cubes of natural numbers.*/

import java.io.*;

class Series2{

public static void main(String args[])throws IOException{

//declare all the variables at the beginning
int n,i,a;
    BufferedReader br = new BufferedReader( 
                new InputStreamReader(System.in));
    System.out.println("Enter the number of terms : ");
    n=Integer.parseInt(br.readLine());

    //loop to generate the number of terms in the series
    for(i=1;i<=n;i++){

        a=i*i*i;

        System.out.print(a+" ");

        }//end of loop

  }//end of main
}//end of class        

Have something to say? Log in to comment on this post.

0 comments