Example Programs

Program 

Write a Program in Java to input a number and check whether it is a Keith Number or not.

Note: A Keith Number is an integer N with ‘d’ digits with the following property:

If a Fibonacci-like sequence (in which each term in the sequence is the sum of the ‘d’ previous terms) is formed, with the first ‘d’ terms being the decimal digits of the number N, then N itself occurs as a term in the sequence.

For example, 197 is a Keith number since it generates the sequence 1, 9, 7, 17, 33, 57, 107, 197, ………..

Some keith numbers are: 14 ,19, 28 , 47 , 61, 75, 197, 742, 1104, 1537……………

Sample

Enter the number : 197

The number is a Keith Number

Enter the number : 14

The number is a Keith Number

Enter the number : 53

The number is a not a Keith Number

Program 

Write a program to input a natural number less than 1000 and display it in words.

Test your program for the given sample data and some random data.

INPUT: 29

OUTPUT: TWENTY NINE INPUT: 17001

OUTPUT: OUT OF RANGE INPUT: 119

OUTPUT: ONE HUNDRED AND NINETEEN INPUT: 500

OUTPUT: FIVE HUNDRED