A basic Keith Number Program
For example M = 197 is a keith number because, 197 has 3 digits, so n = 3 The number(197)appears in the special sequence that has first three terms as 1, 9, 7 and remaining terms evaluated using sum of previous 3 terms. 1, 9, 7, 17, 33, 57, 107, 197, …..
An n digit number M is called Keith number if it appears in a special sequence generated using its digits.
For example
M = 197 is a keith number because,
197 has 3 digits, so n = 3
The number(197)appears in the special sequence that has first three terms as 1, 9, 7 and remaining terms evaluated using sum of previous 3 terms.
1, 9, 7, 17, 33, 57, 107, 197, …..
For more number programs click the link
Unleashed: Important Number Programs for ICSE Part-1
Write a program to accept a number and print whether it is a keith number or not.
FOR EXAMPLE: 746, 404, 219 etc
import java.io.*;
class Keith //An n-digit number with value N is Keith if N is a part of Keith series generated
{
public static void main()throws IOException
{
System.out.println("Enter the number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String num=br.readLine();
int len=num.length();
int nm=Integer.parseInt(num);
int arr[]=new int[len];
int n=nm;
for(int i=0;i<len;i++)
{
int d=n%10;
n/=10;
arr[len-1-i]=d;
}
for(int i=0;i<len;i++)
{
System.out.println(arr[i]);
}
int sum=0,count=0;
while(sum<nm)
{
sum=0;
for(int i=0;i<len;i++)
{
sum+=arr[i];
}
arr[count]=sum;
count++;
if(count>(len-1))
{
count=0;
}
}
if(sum==nm)
{
System.out.println("It is a Keith number");
}
else
{
System.out.println("Not a Keith number");
}
}
}Output:
Enter the number
197
It is a Keith number
To learn how to use Bluej to make java programs watch the video:
https://youtu.be/TRm9r4gFTho
Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

String Methods in Java for ICSE Class 10: 25 Output Questions with Answers
ICSE Class 10 Computer Applications practice on String class methods: length, charAt, indexOf, lastIndexOf, substring, replace, trim, compareTo, equals and more, with 25 board-style output questions and step-by-step answers.