Tuesday, February 14, 2012

BlueJ Program on Tribonacci Series Display


Tribonacci series is like Fibonacci series with slight difference. In this series the latest three numbers are added and the result is displayed.

import java.io.*;
class Max
{
int i,p,m,c,next,n;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void disp()throws Exception
{
p=0;
m=1;
c=1;
System.out.println("Enter the number of elements in the series:");
n=Integer.parseInt(br.readLine());
System.out.print("The series is="+ p+" "+m+" "+c+ " ");
for(i=0;i< n-3;i++)
{
next=p+m+c;
System.out.print(next+ " ");
p=m;
m=c;
c=next;
}
}
public static void main(String args[])throws Exception
{
 Max ob=new Max();
 ob.disp();
}
}


Back To BlueJ Series Display Programs Home Page: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner