Number - based Codes (Class 10)
Classwork - 30/07/2025
___________________________________________________
Question 1
A Dudeney number is a positive integer that is a perfect cube such that
the sum of its digits is equal to the cube root of the number. Write a
program to input a number and check and print whether it is a Dudeney
number or not.
Example:
Consider the number 512.
Sum of digits = 5 + 1 + 2 = 8
Cube root of 512 = 8
As Sum of digits = Cube root of Number hence 512 is a Dudeney number.
Solution →
import java.util.Scanner;
public class DudeneyNumber
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the number: ");
int n = in.nextInt();
int temp=n, sum=0;
int cubeRoot = (int)Math.round(Math.cbrt(n));
while (temp>0)
{
int d = temp % 10;
sum += d;
temp /= 10;
}
if (sum == cubeRoot) {
System.out.println(n + " is a Dudeney number");
}
else {
System.out.println(n + " is not a Dudeney number");
}
}
}
Question 2
Two different numbers are said to be Extreme Numbers (Amicable
Numbers also) if each sum of divisors is equal to the other number.
Amicable Numbers are: (220, 284), (1184, 1210), (2620, 2924), (5020,
5564), (6232, 6368) etc.
Example– 220 and 284 are Amicable Numbers.
Divisors of 220 = 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110
1+2+4+5+10+11+20+22+44+55+110=284
Divisors of 284 = 1, 2, 7, 71, 142
1+2+7+71+142=220
Solution →
import java.util.Scanner;
public class AmicableNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter 1st number= ");
int a = sc.nextInt();
System.out.print("Enter 2nd number: ");
int b = sc.nextInt();
int sumA = 0, sumB = 0;
for (int i = 1; i < a; i++)
{
if (a % i == 0)
{
sumA += i;
}
}
for (int i = 1; i < b; i++)
{
if (b % i == 0)
{
sumB += i;
}
}
if (sumA == b && sumB == a)
{
System.out.println("The numbers are
Amicable Number.");
}
else
{
System.out.println("The numbers are not
Amicable Number");
}
}
}
Question 3
A Duck number is a number which has zeroes present in it, but
there should be no zero present in the beginning of the
number. For example 3210
Solution →
import java.util.Scanner;
public class DuckNumber
{
public static void main(String[] args)
{
int r, n, num;
boolean flag=false;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n;
while (num > 0)
{
r = num % 10;
if(r==0)
{
flag=true;
}
num = num / 10;
}
if(flag)
{
System.out.println("Duck Number");
}
else
{
System.out.println("Not Duck Number");
}
}
}
What is Duck Number?
A Duck number is a number which has zeroes present in it, but there
should be no zero present in the beginning of the number. For example
3210
Question 4
A number is said to be a special number when the sum of the
factorial of its digits is equal to the number itself. Example- 145 is a
Special Number as 1!+4!+5!=145.
A number is said to be Krishnamurthy Number when the sum of
factorial of its digits is equal to the number itself. Example- 145 is a
Krishnamurthy Number as 1!+4!+5!=145.
import java.util.Scanner;
public class SpecialNumber
{
public static void main(String[] args)
{
int n, num, r,
sumOfFactorial = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n;
while (num > 0)
{
r = num % 10;
int fact=1;
for(int i=1;i<=r;i++)
{
fact=fact*i;
}
sumOfFactorial = sumOfFactorial+fact;
num = num / 10;
}
if(n==sumOfFactorial)
{
System.out.println("Special Number" );
}
else
{
System.out.println("Not Special Number" );
}
}
}
What is Special Number?
A number is said to be special number when the sum of factorial of its
digits is equal to the number itself. Example- 145 is a Special Number
as 1!+4!+5!=145.
Question 5
A number is said to be an Ugly number if positive numbers
whose prime factors only include 2, 3, 5.
For example, 6(2×3), 8(2x2x2), 15(3×5) are ugly numbers while 14(2×7) is not ugly since
it includes another prime factor 7. Note that 1 is typically treated as an ugly number.
Solution →
import java.util.Scanner;
public class UglyNumber
{
public static void main(String[] args)
{
int n;
boolean flag=true;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
while (n != 1)
{
if (n % 5 == 0)
{
n /= 5;
}
else if (n % 3 == 0)
{
n /= 3;
}
else if (n % 2 == 0)
{
n /= 2;
}
else
{
flag=false;
break;
}
}
if (flag)
{
System.out.println("Ugly number.");
}
else
{
System.out.println("Not Ugly number.");
}
}
}
Question 6
A number is called a twisted prime number if it is a prime
number and the reverse of this number is also a prime
number.
Solution →
import java.util.Scanner;
public class TwistedPrime
{
public static void main(String[] args)
{
int n, num, r,
rev = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n;
while (num > 0)
{
r = num % 10;
rev = (rev * 10) + r;
num = num / 10;
}
if (prime(n) && prime(rev))
{
System.out.println("Twisted Prime");
}
else
{
System.out.println("Not Twisted Prime");
}
}
static boolean prime(int n)
{
int i = 2;
boolean flag = true;
while (n > i)
{
if (n % 2 == 0)
{
flag = false;
break;
}
i++;
}
return flag;
}
}