Class 9 Icse Number Base Program
Class 9 Icse Number Base Program
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.
import java.util.Scanner;
Output:
Enter number=42
Pronic Number
Magic number is the if the sum of its digits
recursively are calculated till a single digit If the
single digit is 1 then the number is a magic
number. Magic number is very similar with Happy
Number.
Example- 226 is said to be a magic number
2+2+6=10 sum of digits is 10 then again 1+0=1 now we get a single digit
number is 1.if we single digit number will now 1 them it would not a magic
number.
import java.util.Scanner;
Output:
Enter number=226
Magic Number
A tech number can be tech number if its digits are even and the number of
digits split into two number from middle then add these number if the added
number’s square would be the same with the number it will called a Tech
Number.
If the number is split in two equal halves,then the square of sum of these
halves is equal to the number itself. Write a program to generate and print
all four digits tech numbers.
Note: If number of digits is not even then it is not a tech number.
Example:
2025 => 20+25 => 552 => 2025
import java.util.Scanner;
import java.util.Scanner;
if(n==sum)
{
System.out.println("Disarium Number");
}
else
{
System.out.println("Not Disarium Number");
}
}
}
Output:
Enter number=135
Disarium Number
A number is said to be unique , if the digits in it
are not repeated. for example, 12345 is a unique
number. 123445 is not a unique number.
import java.util.Scanner;
If (num == 1) {
System.out.println(num + “ is not a twisted prime number”);
}
Else {
Boolean isPrime = true;
For (int I = 2; I <= num / 2; i++) {
If (num % I == 0) {
isPrime = false;
break;
}
}
If (isPrime) {
Int t = num;
Int revNum = 0;
While (t != 0) {
Int digit = t % 10;
T /= 10;
revNum = revNum * 10 + digit;
}
If (isPrime)
System.out.println(num + “ is a twisted prime number”);
Else
System.out.println(num + “ is not a twisted prime
number”);
}
}
}
Or using function
import java.util.Scanner;
Output:
Enter number=137
Twisted Prime
A twin prime is a prime number that is either 2 less
or 2 more than another prime number—for
example, either member of the twin prime pair (41,
43). In other words, a twin prime is a prime that
has a prime gap of two.
import java.util.Scanner;
Output:
Enter a=5
Enter b=7
Twin Prime
A spy number is a number where the sum of its
digits equals the product of its digits. For example,
1124 is a spy number, the sum of its digits is
1+1+2+4=8 and the product of its digits is
1*1*2*4=8.
import java.util.Scanner;
Output:
Enter number=123
Spy 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.
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;
Output:
Enter number=124
Not Special Number
a Niven number (or harshad number) in a given
number base is an integer that is divisible by the
sum of its digits when written in that base.
import java.util.Scanner;
Output:
Enter number=204
Niven Number
A neon number is a number where the sum of
digits of square of the number is equal to the
number. For example if the input number is 9, its
square is 9*9 = 81 and sum of the digits is 9. i.e. 9
is a neon number.
import java.util.Scanner;
public class NeonNumber
{
public static void main(String[] args)
{
// TODO code application logic here
int n,
sqr = 1,
sum = 0, r;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
sqr = n * n;
while (sqr > 0)
{
r = sqr % 10;
sum = sum + r;
sqr = sqr / 10;
}
if (n == sum)
{
System.out.println("Neon Number");
}
else
{
System.out.println("Not Neon Number");
}
}
}
Output:
Enter number=9
Neon Number
a harshad number (or Niven number) in a given
number base is an integer that is divisible by the
sum of its digits when written in that base.
import java.util.Scanner;
Output:
Enter number=6804
Harshad Number
A happy number is a natural number in a given
number base that eventually reaches 1 when
iterated over the perfect digital invariant function
for. Those numbers that do not end in 1 are -
unhappy numbers.
import java.util.Scanner;
Output:
Enter number=31
Happy Number
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
import java.util.Scanner;
}
}
Output:
Enter number=205
Duck Number
A number is said to be Buzz Number if it ends with
7 or is divisible by 7.
Example: 1007 is a Buzz Number.
import java.util.Scanner;
public class BuzzNumber
{
public static void main(String[] args)
{
int n;
Scanner sc = new Scanner(System.in);
System.out.print("Enter n=");
n = sc.nextInt();
if (n % 10 == 7 || n % 7 == 0)
{
System.out.println("Buzz number");
}
else
{
System.out.println("Not Buzz number");
}
}
}
Output:
Enter n=147
Buzz number
An Automorphic number is a number whose square
“ends” in the same digits as the number itself.
Examples: 5*5 = 25, 6*6 = 36, 25*25 = 625
import java.util.Scanner;
}
}
Output:
Enter number=25
Automorphic Number
Armstrong Number is a positive number if it is
equal to the sum of cubes of its digits is called
Armstrong number and if its sum is not equal to
the number then its not a Armstrong number.
Armstrong Number Program is very popular in java, c language, python etc.
Examples: 153 is Armstrong
(1*1*1)+(5*5*5)+(3*3*3) = 153
import java.util.Scanner;
/**
* @author AFAQ
*/
public class ArmstrongNumber
{
public static void main(String[] args)
{
int n,
cubeSum = 0, num, r;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n;
while (num > 0)
{
r = num % 10;
cubeSum = cubeSum + (r * r * r);
num = num / 10;
}
if (n == cubeSum)
{
System.out.println("Armstrong Number");
}
else
{
System.out.println("Not Armstrong Number");
}
}
}
Output:
Enter number=153
Armstrong Number
A number is called Capricorn or Kaprekar number whose square is divided
into two parts in any conditions and parts are added, the additions of parts is
equal to the number, is called Capricorn or Kaprekar number.
Example: 45
45 = (45)2 = 2025
2025
All parts for 2025:-
202 + 5 = 207 (not 45)
20 + 25 = 45
2 + 025 = 27 (not 45)
import java.util.Scanner;
int square = n * n;
int temp = square;
int contDigits = 0;
Output:
Enter a number=297
Capricorn/Kaprekar number
Two different numbers are said to be so Amicable Numbers 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
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");
}
}
}
Output:
Enter 1st number= 284
Enter 2nd number: 220
The numbers are Amicable Number.
Int a, b;
If (a % b == 0)
Break;
System.out.println(a);
Output:
12
Char ch = ‘F’;
Int m = ch;
M=m+5;
System.out.println(m + “ “ + ch);
Output:
75 F
Int i = 1;
Int d = 5;
Do
D = d * 2;
System.out.println(d);
I++;
Output:
10
20
40
80
160
{
System.out.print(“”);
System.out.println(“WIN”);
Output:
WIN
WIN
System.out.println(arr[0].length()> arr[3].length());
System.out.print(arr[4].substring(0,3));
Output:
False
JAI
Int i;
System.out.println( i );
System.out.println( i * 4 );
Output:
20
Int i;
For( i=5 ; i>=1 ;i--)
If(i%2 ==1)
Continue;
System.out.print( i+ “”);
Output:
42
Int x = 10;
Explanation: Curly braces are optional and without curly braces we can take
only one statement under for loop which should not be declarative
statement. Here we are declaring a variable that’s why we will get compile
time error saying error: variable declaration not allowed here.
{
Public static void main(String[] args)
Int i = 0;
System.out.println(“HELLO GEEKS”);
Explanation: Initialization part of the for loop will be executed only once in
the for loop life cycle. Here we can declare any number of variables but
should be of same type. By mistake if we are trying to declare different data
types variables then we will get compile time error saying error: incompatible
types: String cannot be converted to int.
Int i = 0;
System.out.println(“HELLO ”);
}
Output:
HI
HELLO
Explanation:I n the initialization section we can take any valid java statement
including System.out.println(). In the for loop initialization section is executed
only once that’s why here it will print first HI and after that HELLO
System.out.println(“HELLO ”);
Output:
HELLO (Infinitely)
Explanation: In the conditional check we can take any valid java statement
but should be of type Boolean. If we did not give any statement then it
always returns true.
System.out.println(“GEEKS");
Output:
GEEKS WELCOME(Infinitely)
192 x 1 = 192
192 x 2 = 384
192 x 3 = 576
if (isFascinating)
System.out.println(num + " is a Fascinating Number");
else
System.out.println(num + " is not a Fascinating Number");
}
}
A number is said to Bouncy number if the digits of the
number are unsorted.
For example,
22344 - It is not a Bouncy number because the digits are
sorted in ascending order.
774410 - It is not a Bouncy number because the digits are
sorted in descending order.
155349 - It is a Bouncy number because the digits are
unsorted.
A number below 100 can never be a Bouncy number.
Write a program in java to accept a number. Check and
display whether it is a Bouncy number or not.
import java.util.Scanner;
if (n < 100) {
System.out.println(n + " is not a Bouncy Number.");
return;
}
int t = n;
boolean isIncreasing = true, isDecreasing = true;
t = n;
prev = t % 10;
while (t != 0) {
int d = t % 10;
if (d < prev) {
isDecreasing = false;
break;
}
prev = d;
t /= 10;
}
int count = 0;
int p = 0;
int binNum = 0;
while (n > 0) {
int d = n % 2;
if (d == 1)
count++;
binNum += (int)(d * Math.pow(10, p));
p++;
n /= 2;
}
if (count % 2 == 0)
System.out.println("Output: Evil Number");
else
System.out.println("Output: Not an Evil Number");
}
}
A Smith number is a composite number, whose sum of the
digits is equal to the sum of its prime factors. For example:
4, 22, 27, 58, 85, 94, 121 ………. are Smith numbers.
Write a program in Java to enter a number and check
whether it is a Smith number or not.
Sample Input: 666
Sum of the digits: 6 + 6 + 6 = 18
Prime factors are: 2, 3, 3, 37
Sum of the digits of the prime factors: 2 + 3 + 3 + (3 + 7) =
18
Thus, 666 is a Smith Number.
import java.util.Scanner;
if (n <= 0) {
System.out.println(n + " is not a Smith Number.");
return;
}
if (isComposite && n != 1) {
int sumDigits = 0;
int t = n;
while (t != 0) {
int d = t % 10;
sumDigits += d;
t /= 10;
}
int sumPrimeDigits = 0;
t = n;
for(int i = 2; i < t; i++) {
while(t % i == 0) {
t /= i;
int temp = i;
while (temp != 0) {
int d = temp % 10;
sumPrimeDigits += d;
temp /= 10;
}
}
}
if(t > 2) {
while (t != 0) {
int d = t % 10;
sumPrimeDigits += d;
t /= 10;
}
}
if (sumPrimeDigits == sumDigits)
System.out.println(n + " is a Smith Number.");
else
System.out.println(n + " is not a Smith Number.");
}
else {
System.out.println(n + " is not a Smith Number.");
}
}
}
An *Adam Number* is a number where the square of the
number and the square of its reverse, when reversed, are
equal.
✅ *Example*:
- Number: 12
- Reverse: 21
- Square: 144
- Reverse of (21² = 441) → 144
✔ Adam Number
System.out.print("Enter n: ");
int n = in.nextInt();
if (isComposite && i != 1) {
int num = i;
while (num > 9) {
int sum = 0;
while (num != 0) {
int d = num % 10;
num /= 10;
sum += d;
}
num = sum;
}
if (num == 1) {
count++;
System.out.print(i + " ");
}
}
}
System.out.println();
System.out.println("Frequency of composite magic numbers: " +
count);
}
}
ANSWER
import java.util.Scanner;
return c == 2;
}
if (n % 2 != 0) {
System.out.println("INVALID INPUT. NUMBER IS ODD.");
return;
}
int a = 3;
int b = 0;
while (a <= n / 2) {
b = n - a;
if (isPrime(a) && isPrime(b)) {
System.out.println(a + ", " + b);
}
a += 2;
}
}
}
A Prime-Adam integer is a positive integer (without leading
zeros) which is a prime as well as an Adam number.
Prime number: A number which has only two factors, i.e. 1
and the number itself.
Example: 2, 3, 5, 7 … etc.
Adam number: The square of a number and the square of its
reverse are reverse to each other.
Example: If n = 13 and reverse of 'n' = 31, then,
(13)2 = 169
(31)2 = 961 which is reverse of 169
thus 13, is an Adam number.
Accept two positive integers m and n, where m is less than n
as user input. Display all Prime-Adam integers that are in
the range between m and n (both inclusive) and output them
along with the frequency, in the format given below:
Test your program with the following data and some random
data:
Example 1
INPUT:
m=5
n = 100
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:
11 13 31
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 2
INPUT:
m = 100
n = 200
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:
101 103 113
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 3
INPUT:
m = 50
n = 70
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:
NIL
FREQUENCY OF PRIME-ADAM INTEGERS IS: 0
Example 4
INPUT:
m = 700
n = 450
OUTPUT:
INVALID INPUT
1. Home
2. /
3. Java Number Programs (ISC Classes 11 / 12)
4. /
5. Prime-Adam Integer Java Program
return rev;
}
return c == 2;
}
if (m >= n) {
System.out.println("INVALID INPUT");
return;
}
System.out.println();
System.out.println("FREQUENCY OF PRIME-ADAM INTEGERS IS: " + count);
}
}
Write a program to input a number and check and print
whether it is a Pronic number or not. [Pronic number is the
number which is the product of two consecutive integers.]
Examples:
12 = 3 * 4
20 = 4 * 5
42 = 6 * 7
Import java.util.Scanner;
If (I * (I + 1) == num) {
isPronic = true;
break;
}
If (isPronic)
Else
An Abundant number is a number for which the sum of its proper factors is
greater than the number itself. Write a program to input a number and check
and print whether it is an Abundant number or not.
Example:
Import java.util.Scanner;
Int sum = 0;
If (n % I == 0)
Sum += I;
If (sum > n)
Else
Import java.util.Scanner;
Int digitSum = 0;
While (num != 0) {
Num /= 10;
digitSum += digit;
/*
* 0 as input
*/
Else
Int n, num, r,
Rev = 0;
System.out.print(“Enter number=”);
N = sc.nextInt();
Num = n;
R = num % 10;
System.out.println(“Twisted Prime”);
Else
Int I = 2;
While (n > i)
If (n % 2 == 0)
Flag = false;
Break;
I++;
Return flag;
A tech number can be tech number if its digits are even and the number of
digits split into two number from middle then add these number if the added
number’s square would be the same with the number it will called a Tech
Number.
If the number is split in two equal halves,then the square of sum of these
halves is equal to the number itself. Write a program to generate and print all
four digits tech numbers.
Note: If number of digits is not even then it is not a tech number.
Example:
Import java.util.Scanner;
sumSquare = 0;
System.out.print(“Enter number=”);
N = sc.nextInt();
Num = n;
Digits++;
If (digits % 2 == 0)
Num = n;
leftNumber = num % (int) Math.pow(10, digits / 2);
if (n == sumSquare)
System.out.println(“Tech Number”);
Else
Else
Output:
Enter number=2025
Tech Number
First 15 Narcissistic Numbers
Write a Java program to generate and show the first 15 narcissistic decimal numbers.
A Narcissistic decimal number is a non-negative integer, n that is equal to the sum of the
m-th powers of each of the digits in the decimal representation of n, where m is the
number of digits in the decimal representation of n.
if n is 153
Sample Solution:
Java Code:
// https://rosettacode.org/
if(is_narc_dec_num(n)){
System.out.print(n + " ");
ctr++;
System.out.println();
int x = str1.length();
long sum_num = 0;
for(char c : str1.toCharArray()){
return sum_num == n;
Copy
Sample Output:
0 1 2 3 4 5 6 7 8 9 153 370 371 407 1634
public class TriangleArea {
double sideA = 5;
double sideB = 6;
double sideC = 7;
double s = (a + b + c) / 2.0;
Double x1 = 10;
Double y1 = 10;
Double x2 = 20;
Double y2 = 20;
}
Public static double calculateDistance(double x1, double y1, double x2,
double y2) {