Solved ProgramsICSEClass 10Computer Applications

Basic Important Number programs for ICSE part-5

To learn more java programshttps://wordpress-343193-1101484.cloudwaysapps.com/string-programs-part-5

Updated
Solved Programs

To learn more java programs
String Programs part 5

Number programs ICSE
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()); 
        String n=Integer.toString(num);
        int len=n.length(); 
        int arr[]=new int[len];               // the last len terms of the series
        for(int i=0;i<len;i++) 
            arr[i]=n.charAt(i)-'0';           // start with the digits of the number
        int term=0,pos=0;
        while(term<num) 
        { 
            term=0;
            for(int i=0;i<len;i++)            // next term = sum of the last len terms
                term+=arr[i];
            arr[pos]=term;                    // replace the oldest term
            pos=(pos+1)%len;
        } 
        if(term==num && len>1) 
            System.out.println("It is a Keith number"); 
        else  
            System.out.println("It is not a Keith number"); 
    } 
}

For videos related to java programming
http://www.youtube.com/user/trushnatej