Sunday, July 3, 2011

Programs on series printing using BlueJ


Today I will show how to print two specified series using BlueJ. Our first Series is like
 3,33,333,3333,33333,333333,3333333,33333333

Here user will specify the number of elements in the series and accordingly the series will be printed. Here is the codes of the program.

import java.io.*;

class Series
{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,x,n;
  public void take() throws Exception
 {
  System.out.println("Enter the number of elements in the series:");
  n=Integer.parseInt(br.readLine());
x=0;
for (i=0;i< n;i++)
{
  x=x*10+3;
System.out.print(" "+x);

}
}
  public static void main(String args[]) throws Exception
  {
   Series ob=new Series();
   ob.take();
   }
   }

Our second series is similar to the first series with a slight difference. Here the series looks like:
 1 9 1 99 1 999 1 9999 1 99999 1 999999

As the previous series program, here the elements 9,99,999 are generated and ‘1’ and the numbers are alternately printed. This is the difference.


import java.io.*;

class Series1
{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,x,n;
  public void take() throws Exception
 {
  System.out.println("Enter the number of elements in the series:");
  n=Integer.parseInt(br.readLine());
x=0;
for (i=0;i< n;i++)
{
 if(i%2==0)
System.out.print(" "+1);
else
{
 x=x*10+9;
System.out.print(" "+x);
}
}
}
  public static void main(String args[]) throws Exception
  {
   Series1 ob=new Series1();
   ob.take();
   }
   }

Back To BlueJ Series Display Programs Home Page: CLICK HERE

2 comments:

  1. program to print this series
    S=(1*2)+(2*3)+...............(19*20)
    please help me to solve this series

    ReplyDelete

Subscribe via email

Enter your email address:

Delivered by FeedBurner