YP ICSE 10th Number Based Programs
YP ICSE 10th Number Based Programs
****************************************************************************************************************************************************************
Master Program of Number programs (Based on number’s digits) (22 Programs)
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
a = n;
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit
if( dig%2 == 0 )
{
esum = esum + dig; //Q5→ To get sum of even digits.
eprod = eprod * dig; //Q6→ To get product of even digits.
ecnt++; //Q7→ To get total number of even digits
}
else
{
osum = osum + dig //Q8→ To get the sum of odd digits.
oprod = oprod * dig; //Q9→ To get product of odd digits.
ocnt++; //Q10→ To get total number of odd digits
}
//Q11→ To get sum of cube of digits(Armstrong)
asum = asum + Math.pow( dig, 3);
//Q15→ To check Duck number (A Duck number is number which has zeroes present in it.)
if( dig == 0 )
zcnt++ ;
} // End of while loop
//Q14→ To check Super six number (A Super Six number is number which contains at least two or
more sixes.)
if( sscnt >= 2 )
System.out.println(“ It is Super six Number”) ;
else
System.out.println(“It is not Super six Number”) ;
//Q15→ To check Duck number (A Duck number is number which has zeroes present in it.)
if( zcnt>0 ) //
System.out.println(“ It is Duck Number”) ;
else
System.out.println(“It is not Duck Number”) ;
//Q16→ To check Niven number (A Niven number is that number which is divisible by its sum of
digits.)
if( a%sum == 0 )
System.out.println(a + " is Niven number");
else
System.out.println(a + " is not Niven number");
//Q17→ To check Spy number (A number is spy number if the sum of its digits equals the product of
its digits.)
if( sum == prod )
System.out.println(“ It is Spy Number”) ;
else
System.out.println(“It is not Spy Number”) ;
//Q18→ To check Special 2-digit Number (A number is a special two-digit number if the sum of its
digits is added to the product of its digits, the result is equal to the original two-digit number.
if( (sum+prod) == a && cnt == 2 )
****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→2
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
System.out.println(“ It is Special 2-digit Number”) ;
else
System.out.println(“It is not Special 2-digit Number”) ;
//Q19→ To check Cyclo number (Cyclo number is the number which has its first and last digit is
same.) int ld = n%10;
if( ld == dig )
System.out.println(a + " is Cyclo number");
else
System.out.println(a + " is not Cyclo number");
//Q20→ To check Micro number (Micro number is the number which has at least one even digit.)
if( cnt > 0 )
System.out.println(a + " is Micro number");
else
System.out.println(a + " is not Micro number");
} // End of main()
} // End of class()
****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→3
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q1→ WAP to input a number and find sum of digits and product of digits and total number of digits.
(Q1,2)
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int sum=0, prod=1,cnt=0;
a = n;
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit
****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→4
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q2→ WAP to input a number and find followings. (Q4 to 10)
a) Total number of even digits
b) Total number of odd digits
c) Sum of even digits
d) Sum of odd digits
e) Product of even digit
f) Product of odd digit
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int esum=0, osum=0, eprod=1, oprod=1, ecnt=0, ocnt=0;
a = n;
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit
if( dig%2==0 )
{
esum = esum + dig ;
ecnt++;
eprod = eprod * dig ;
}
else
{
osum = osum + dig ;
ocnt++;
oprod = oprod * dig ;
}
}
System.out.printlm(“sum of even digits = “+esum);
System.out.printlm(“Product of evem digits = “+eprod);
System.out.printlm(“sum of odd digits = “+osum);
System.out.printlm(“Product of odd digits = “+oprod);
System.out.printlm(“Total number of even digits = “+ecnt);
System.out.printlm(“Total number of evem digits = “+ocnt);
}
}
****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→5
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q3→ WAP to input a number and find its reverse number and also check it is palindrome or not.
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int rev=0;
a = n; //copy of n number
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit
}
System.out.printlm(“reverse number = “ + rev);
if(a==rev)
{
System.out.println(“It is palindrome number”);
}
else
{
System.out.println(“It is not palindrome number”);
}
}
****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→6
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q3→ WAP to input a number and check it is Armstrong number or not.
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int sum=0;
a = n; //copy of n number
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit
if(a==sum)
{
System.out.println(“It is Armstrong number”);
}
else
{
System.out.println(“It is not Armstrong number”);
}
}
****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→7
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q14→ To check Super six number (A Super Six number is number which contains at least two or
more sixes.)
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int cnt=0;
a = n; //copy of n number
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit
if( dig==6 )
{
cnt++;
}
}
****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→8