+ 6

Keith number

Is it possible to make a program in java to check whether the entered number is keith number or not without using array? A n digit number x is called Keith number if it appears in a special sequence (defined below) generated using its digits. The special sequence has first n terms as digits of x and other terms are recursively evaluated as sum of previous n terms. Input : x = 197 Output : Yes 197 has 3 digits, so n = 3 The number is Keith because it 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, ..... Input : x = 12 Output : No The number is not Keith because it doesn't appear in the special sequence generated using its digits. 1, 2, 3, 5, 8, 13, 21, ..... Input : x = 14 Output : Yes 14 is a Keith number since it appears in the sequence, 1, 4, 5, 9, 14, ...

12th Jan 2019, 2:18 AM
mn121
mn121 - avatar
6 Answers
+ 1
https://code.sololearn.com/cKeCv3X81Cf5/?ref=app I used int for the sum and String to store the needed numbers.
12th Jan 2019, 8:44 PM
Denise Roßberg
Denise Roßberg - avatar
5th Aug 2019, 10:34 AM
Mritunjay Kumar
Mritunjay Kumar - avatar
+ 3
Hi! Can you mention what a keith number is? It is possible to solve anything in programming. so don't worry, your question has an answer
12th Jan 2019, 5:07 PM
Seniru
Seniru - avatar
+ 1
Denise Roáșžberg Thanks... 😁😁
13th Jan 2019, 12:51 PM
mn121
mn121 - avatar
0
I would say the trick is to remove the first number if you have the sum. 197: 1 + 9 + 7 = 17 9 + 7 + 17 = 33 7 + 17 + 33 = 57 17 + 33 + 57 = 107 33 + 57 + 107 = 197 If sum = input --> keith number If sum > input --> not a keith number It is like a fibonacci sequence.
12th Jan 2019, 9:07 PM
Denise Roßberg
Denise Roßberg - avatar
0
Write a program to find Keith number using while loop in java
24th Oct 2024, 6:46 AM
Gangana Vasundhara
Gangana Vasundhara - avatar