Tuesday, December 6, 2022

BlueJ Program On Keith Number

 What is Keith Number and How to Check


Keith Number: Let's check the number 742 is a Keith number or not.

First, we will separate each digit, as 7, 4, 2

To find the next term of the above-created series, we add these digits (i.e. 7+4+2), and the resultant (13) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13

To find the next term of the above series, we add the last three terms (i.e. 13+2+4), and the resultant (19) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19

To find the next term of the above series, we add the last three terms (i.e. 19+13+2), and the resultant (34) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34

To find the next term of the above series, we add the last three terms (i.e. 34+19+13), and the resultant (66) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66

To find the next term of the above series, we add the last three terms (i.e. 66+34+19), and the resultant (119) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66, 119

To find the next term of the above series, we add the last three terms (i.e. 119+66+34), and the resultant (219) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66, 119, 219

To find the next term of the above series, we add the last three terms (i.e. 219+119+66), and the resultant (404) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66, 119, 219, 404

To find the next term of the above series, we add the last three terms (i.e. 404+219+119), and the resultant (742) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66, 119, 219, 404, 742

As 742 is present in the series, 742 is a Keith Number.


Program On Keith Number

import java.util.*;
public class Keith
{
    int i,arr[],n,c=0;
    Scanner sc=new Scanner(System.in);
    void take()
    {
        int sum=0;
        System.out.print("\nEnter the number:");
        n=sc.nextInt();
        for(i=n;i>0;i=i/10)
        c++;
        arr=new int[c];
        int n1=c;
        for( i=n;i>0;i=i/10)
        arr[--n1]=i%10;
        System.out.print("\nSeries is: ");
        for(i=0;i<c;i++)
        {
        System.out.print(" "+arr[i]);
        if(n==arr[i])
        System.out.print(n + " is Keith Number");
        }
        while(true)
        {
            sum=0;        
        for(i=0;i<c;i++)
        {
            sum+=arr[i];             
        }
        System.out.print(" "+sum);
        if(n==sum)
        {
            System.out.print("\n"+ n + " is a Keith Number");
            break;
        }
        else if(n<sum)
        {
            System.out.print("\n"+ n + " is not a Keith Number");
            break;
        }
        else
        {
            for(i=0;i<c-1;i++)
            {
              arr[i]=arr[i+1];  
            }
            arr[i]=sum;
        }        
    }
    }
public static void main(String[] args) {
Keith ob=new Keith();
ob.take();
}
}


Other Programs On Numbers: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner