#### Blue Java Program For Keith Number

If a Fibonacci sequence (in which each term in the sequence is the sum of the previous t terms) is formed, with is the first ‘t’ terms being the decimal digits of the number n, then n itself occurs as a term in the sequence.
For example,
14 is a Keith number
Because it generates the sequence:-
1, 4, 5, 9, 14
(1+4)=5, (5+9)=14, (9+14)=23………
Some keith numbers are: 14 ,19, 28 , 47 , 61, 75, 197….
import java.io.*;
import java.util.*;
class Keith
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print(“Enter the number : “); //inputting the number
int n=sc.nextInt();

int copy=n;
String s=Integer.toString(n);
int d=s.length(); //finding the number of digits (d) in the number
int arr[]=new int[n]; //array for storing the terms of the series

for(int i=d-1; i&gt;=0; i–)
{
arr[i]=copy%10; //storing the digits of the number in the array
copy=copy/10;

}

int i=d,sum=0;
while(sum&lt;n) //finding the sum till it is less than the number
{
sum = 0;
for(int j=1; j&lt;=d; j++) //loop for generating and adding the previous ‘d’ terms
{
sum=sum+arr[i-j];
}
arr[i]=sum; //storing the sum in the array
i++;
}

if(sum==n) //if sum is equal to the number, then it is a Keith number
System.out.println(“The number is a Keith Number”);
else
System.out.println(“The number is a not a Keith Number”);
}
}