Tribonacci Series in Java

The Tribonacci series is similar to the Fibonacci series. The Tribonacci sequence is a generalization of the Fibonacci sequence where each term is the sum of the three preceding terms.

Tribonacci Series

A Tribonacci sequence or series is a sequence of integers such that each term from the fourth onward is the sum of the previous three terms. The Tribonacci sequence can be defined as follows:

T0=0,
T1=T2=1
Tn=Tn-1+Tn-2+Tn-3 (n≥3)

In other words, we can say that each term of the series is the sum of the previous three terms. The first few terms of Tribonacci series are:

0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513, 35890, 66012, 121415, 223317, 410744, 755476, 1389537, 2555757, 4700770, 8646064, 15902591, 29249425, 53798080, 98950096, 181997601, 334745777, 615693474, 1132436852… so on.

Tribonacci Series Java Program

In the Tribonacci sequence, the first three terms are initialized. From the fourth and onwards, we sum up the last three terms to get the next term.

Let's implement the logic in a Java program.

TribonacciSeries.java

Output:

Enter No. of terms: 15
Tribonacci Series is given below: 
0	1	1	2	4	7	13	24	44	81	149	274	504 927	1705	

Find Nth Term of the Tribonacci Series

NthTribonacciTerm.java

Output:

Enter the term: 15
The 15th term of the Tribonacci series is: 1705