Wednesday, August 31, 2011

BlueJ Program To Display The Series 0,3,8,15,24


In this BlueJ program the series 0,3,8,15,24,…… will be displayed up to ‘n’ elements.
Codes of the program is given below:

class Position
{
int i,x=0,b=3;
public void show(int n)
{
for(i=0;i< n;i++)
{
 System.out.print(" "+x);
 x=x+b;
 b=b+2;
}
}
}

In this program, the series shows that a values starting from 3 is added to its previous value and the sum is displayed. The value which is added to the previous value in the series is incremented by ‘2’ and the operation of display, add and increment is continued.

In the above program ‘x’ is displayed, ‘b’ is the value added to ‘x’ in each iteration and after that value of ‘b’ is incremented by 2.

Back To BlueJ Series Display Programs Home Page: CLICK HERE

7 comments:

  1. write a program to input a sentence and print the sentence before and after removing all the vowels in the string

    ReplyDelete
  2. This program can be found in my site, go through Removing vowels.

    ReplyDelete
  3. Sir, may you explain call by refference

    ReplyDelete
    Replies
    1. In my site, search with 'call be reference' and you will get the answer.

      Delete
  4. import java.io.*;
    import java.util.*;
    class series4
    {
    public static void main(String args[])
    {
    int n,i,x=0,b=3;
    Scanner sc=new Scanner(System.in);
    System.out.println("Input the number of terms");
    n=sc.nextInt();
    for(i=0;i<n;i++)
    {
    System.out.print(" "+x);
    x=x+b;
    b=b+2;
    }
    }
    }


    This is the perfect way

    ReplyDelete

Subscribe via email

Enter your email address:

Delivered by FeedBurner