To learn more java programs
https://java4school.com/string-programs-part-5
Happy Number:
The happy number is an important number program can be defined as a number that will result in one when it is replaced by the sum of the square of its digits repeatedly.
import java.io.*;
class Happy
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int num=Integer.parseInt(br.readLine());
int sum=0;
double a=0;
while(num>=0)
{
a=num%10;
a=Math.pow(a,2);
sum+=a;
num=num/10;
if(num==0)
{
if(sum<10)
break;
else
{
num=sum;
sum=0;
continue;
}
}
}
if(sum==1)
System.out.println("It is a happy number");
else
System.out.println("It is a happy number");
}
}
Keith number:
An n-digit number Num is a Keith Number if it forms a Fibonacci-like sequence that begins with the digits of the number itself. For example, 197 is a Keith number since it generates the sequence 1, 9, 7, 1+9+7=17, 9+7+17=33, 7+17+33=57, +17+33+57=107,33+57+107=197
The first few keith numbers are 14, 19, 28, 47, 61, 75, 197
import java.io.*;
class KEITH
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int num=Integer.parseInt(br.readLine());
int len=n.length();
int count=0,rem=0,num=n;
int arr[]=new int[num];
do
{
rem=num%10;
num=num/10;
arr[i]=rem;
} while(num!=0);
for(int i=0;i<num;i++)
{
arr[i+len]=arr[i]+arr[i+1];
count++;
if(arr[i+len]==num || arr[i+len]>num)
break;
}
if(arr[count]==num)
System.out.println("It is a Keith number");
else
System.out.println("It is a not Keith number"); } }
For videos related to java programming http://www.youtube.com/user/trushnatej