Tribonacci Number Java

In this section, we will learn what is Tribonacci number and also create Java programs to that calculates the Tribonacci number. The Tribonacci number program is frequently asked in Java coding interviews and academics.

Tribonacci Number

Tribonacci numbers are the same as Fibonacci numbers. We can get the Tribonacci number by adding the previous three terms. The first three terms are a(0) = a(1) = 0 and a(2) = 1. It is an OEIS sequence A000073.

By using these three terms, we can calculate the next Tribonacci number. The general formula for Tribonacci numbers is:

Tribonacci Number Example

First few Tribonacci numbers are 0, 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.

Algorithm

Tribonacci Number Java Program Using Recursion

TribonacciNumbers.java

Output:

0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 5768 10609

Hence, we can say that the terms generated by the Tribonacci series are called Tribonacci numbers.

Find Nth Number of the Tribonacci Series

NthTribonacciNumber.java

Output:

Enter the term: 12
12th Tribonacci number is: 274