★★★★★
"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."
Ria Mukherjee
Parent
ICSE Class 10 · Computer Applications (Java) · Special number programs 2027
Special number programs in Java for ICSE ask you to test whether a number such as 1124 or 156 has a named property: spy, Niven, neon, Armstrong and a dozen more. They look like seventeen different programs. They are really one loop that peels off the last digit, used seventeen ways. This page gives the definitions in one table, the template once, and full programs with Scanner input, comments, variable tables and sample runs from Java 21. In our live mini batch each new number is written from the template, not memorised.
Live online · 17 definitions in one table · one digit template · every program run in Java 21 · first class free
Start here
The ICSE Java course where the mini batch builds these programs, the Class 11 and 12 Computer Science course where ISC asks for the same numbers inside classes, and the data structures course for a student curious about how fast these loops really are.

The batch / ICSE CA
Class 9 and 10 Computer Applications in a mini batch, where every special number is written from one digit template and run in BlueJ.
Open the course →
Next step / ISC
For students moving to ISC Computer Science, where these numbers come back as class methods and with recursion.
Open the course →
Beyond the syllabus / DSA
For the student who asks why a range scan is slow and wants to count the steps properly.
Open the course →Ans. The short version
Special number programs in Java for ICSE test a number for a named property using its digits. A spy number has equal digit sum and digit product (1124); a Niven number is divisible by its digit sum (156); a neon number equals the digit sum of its square (9); an Armstrong number equals the sum of its digits each raised to the number of digits (153); a duck number has a zero after its first non-zero digit (4070). All of them use one loop: d = n % 10, use d, n = n / 10. Modern Age Coders teaches these live in a Tuesday and Wednesday mini batch in India, or personalised one to one.
Q1. What does each special number mean?
Each special number is defined by one rule about its digits, factors or square. The example in every row was recomputed in Java. The last column names the change you make to the digit template for that number.
| Number | Rule in one sentence | Example, checked | What changes in the template |
|---|---|---|---|
| Spy | Sum of digits equals product of digits | 1124: 1+1+2+4 = 8 = 1x1x2x4 | Keep a sum and a product |
| Niven (Harshad) | Divisible by the sum of its digits | 156: sum 12, 156 / 12 = 13 | Sum, then n % sum == 0 |
| Neon | Sum of the digits of its square equals the number | 9: 81, 8+1 = 9 | Run the loop on n * n |
| Armstrong | Sum of each digit raised to the number of digits equals the number | 153 = 1+125+27; 1634 | Count digits first, add Math.pow(d, k) |
| Duck | Has a zero somewhere after its first non-zero digit | 4070 yes; 0045 no | Read as a String, test charAt |
| Magic | Adding the digits again and again ends at 1 | 199, 19, 10, 1 | Repeat the sum while the result is above 9 |
| Perfect | Sum of its factors below itself equals the number | 28 = 1+2+4+7+14 | No digits: loop over factors |
| Automorphic | Its square ends in the number itself | 76: 5776 | Compare n * n % 10k with n |
| Disarium | Sum of each digit raised to its position from the left equals the number | 135 = 1+9+125 | Power k, then k-- each pass |
| Special (Krishnamurthy) | Sum of the factorials of its digits equals the number | 145 = 1!+4!+5! | Add fact(d) |
| Buzz | Divisible by 7 or ends in 7 | 49 and 107 | No loop: n % 7 and n % 10 |
| Pronic | Product of two consecutive integers | 56 = 7x8 | Loop i while i * (i + 1) <= n |
| Sunny | The next number, n + 1, is a perfect square | 80: 81 = 9x9 | Math.sqrt(n + 1) has no fraction |
| Tech | Even digit count; square of the sum of its two halves equals the number | 2025: (20+25)2 | Split with / and % by 10k/2 |
| Happy | Replacing it by the sum of the squares of its digits, again and again, ends at 1 | 19, 82, 68, 100, 1 | Add d * d, repeat |
| Palindrome number | Reads the same reversed | 12321 | Build rev = rev * 10 + d |
| Twisted prime | Prime, and still prime with its digits reversed | 13 and 31 | Reverse, then two prime checks |
We do not attach board years to these numbers. A year tag is only worth printing once it has been checked against the actual paper, and the programs here are written to teach the method, not to copy a question. Schools sometimes define a number slightly differently (Magic and Duck vary most), so when a question gives its own definition, that definition wins.
Q2. Is there one method that works for all of them?
Yes. Take the last digit with n % 10, use it, and drop it with n / 10, until n is 0. Work on a copy so the original number is still there for the final comparison.
int t = n; // copy: keep n for the answer
while (t > 0) {
int d = t % 10; // 1. take the last digit
... use d ... // 2. sum, product, power, factorial
t = t / 10; // 3. drop the last digit
}
// now compare the result with n
Only step 2 changes from number to number. Steps 1 and 3 never change.
| Pass | d = t % 10 | sum | product | t after |
|---|---|---|---|---|
| start | none | 0 | 1 | 1124 |
| 1 | 4 | 4 | 4 | 112 |
| 2 | 2 | 6 | 8 | 11 |
| 3 | 1 | 7 | 8 | 1 |
| 4 | 1 | 8 | 8 | 0, loop ends |
The dry run for 1124: sum 8 equals product 8, so 1124 is a spy number. Notice the product starts at 1 and the sum at 0; starting the product at 0 is the most common reason a spy program says no to every number.
The loop destroys t. If you loop on n itself, the final sum == n compares against 0 and every answer is wrong.
The template meets the digits from the right. That is fine for sums and products; for position-based rules such as Disarium, count the digits first and count down.
For Niven, a 0 input would mean dividing by a digit sum of 0. One n > 0 test in the condition avoids the crash.
Q4. What about Armstrong, duck, magic and perfect numbers?
Armstrong needs the digit count before the loop. Duck needs the number as text, because an int cannot remember leading zeros. Magic repeats the template inside another loop. Perfect does not use digits at all; it loops over possible factors.
import java.util.Scanner;
class ArmstrongN {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
int k = String.valueOf(n).length(); // number of digits
int t = n, sum = 0;
while (t > 0) {
int d = t % 10;
sum = sum + (int) Math.pow(d, k); // digit raised to k
t = t / 10;
}
if (sum == n)
System.out.println(n + " is an Armstrong number");
else
System.out.println(n + " is not an Armstrong number (sum = " + sum + ")");
}
}
Math.pow returns a double, so the (int) cast is needed before adding to an int sum.
| Variable | Type | Purpose |
|---|---|---|
| n | int | the number entered |
| k | int | number of digits |
| t | int | working copy of n |
| d | int | the last digit |
| sum | int | sum of d to the power k |
Enter a number: 1634 1634 is an Armstrong number Enter a number: 371 371 is an Armstrong number Enter a number: 1220 1220 is not an Armstrong number (sum = 33)
Many textbook versions cube every digit, which only works for three-digit numbers. Using k makes 1634 work too.
import java.util.Scanner;
class Duck {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number: ");
String s = sc.next(); // read as text so leading zeros survive
int i = 0;
while (i < s.length() && s.charAt(i) == '0')
i++; // skip the leading zeros
boolean duck = false;
for (int j = i + 1; j < s.length(); j++) {
if (s.charAt(j) == '0') {
duck = true; // a zero after the first real digit
break;
}
}
System.out.println(s + (duck ? " is a Duck number" : " is not a Duck number"));
}
}
If you read the number with nextInt, 0703 arrives as 703 and the leading zero is lost before you can test it.
| Variable | Type | Purpose |
|---|---|---|
| s | String | the number as typed |
| i | int | index of the first non-zero digit |
| j | int | loop counter after that digit |
| duck | boolean | true once a later zero is found |
Enter the number: 4070 4070 is a Duck number Enter the number: 0703 0703 is a Duck number Enter the number: 0045 0045 is not a Duck number Enter the number: 5678 5678 is not a Duck number
0703 qualifies through the zero between 7 and 3; 0045 has only leading zeros.
import java.util.Scanner;
class MagicPerfect {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
// Magic: keep adding the digits until one digit is left
int m = n;
while (m > 9) {
int s = 0;
while (m > 0) {
s = s + m % 10;
m = m / 10;
}
m = s;
}
System.out.println(n + (m == 1 ? " is" : " is not") + " a Magic number (ends at " + m + ")");
// Perfect: the factors below n add up to n
int f = 0;
for (int i = 1; i < n; i++)
if (n % i == 0)
f = f + i;
System.out.println(n + (f == n ? " is" : " is not") + " a Perfect number (factor sum = " + f + ")");
}
}
The outer while keeps going until one digit is left; the inner while is the template.
| Variable | Type | Purpose |
|---|---|---|
| n | int | the number entered |
| m | int | repeated digit sum |
| s | int | digit sum of one round |
| f | int | sum of factors below n |
| i | int | possible factor |
Enter a number: 199 199 is a Magic number (ends at 1) 199 is not a Perfect number (factor sum = 1) Enter a number: 28 28 is a Magic number (ends at 1) 28 is a Perfect number (factor sum = 28) Enter a number: 50 50 is not a Magic number (ends at 5) 50 is not a Perfect number (factor sum = 43)
199 is prime, so its only factor below itself is 1.
import java.util.Scanner;
class SpecialDisarium {
static int fact(int d) { // d! for one digit
int f = 1;
for (int i = 2; i <= d; i++)
f = f * i;
return f;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
int k = String.valueOf(n).length(); // position of the last digit
int t = n, sf = 0, sp = 0;
while (t > 0) {
int d = t % 10;
sf = sf + fact(d); // Special: add d!
sp = sp + (int) Math.pow(d, k); // Disarium: d to the power of its position
k--; // the next digit sits one place to the left
t = t / 10;
}
System.out.println("Sum of digit factorials = " + sf + (sf == n ? ", Special number" : ", not Special"));
System.out.println("Sum of positional powers = " + sp + (sp == n ? ", Disarium number" : ", not Disarium"));
}
}
The loop meets the rightmost digit first, so its position is k, the digit count, and k falls by one each pass.
| Variable | Type | Purpose |
|---|---|---|
| n | int | the number entered |
| k | int | position of the current digit |
| t, d | int | working copy, last digit |
| sf | int | sum of digit factorials |
| sp | int | sum of positional powers |
| f, i | int | factorial and its counter, in fact() |
Enter a number: 145 Sum of digit factorials = 145, Special number Sum of positional powers = 142, not Disarium Enter a number: 135 Sum of digit factorials = 127, not Special Sum of positional powers = 135, Disarium number Enter a number: 89 Sum of digit factorials = 403200, not Special Sum of positional powers = 89, Disarium number
Number palindromes and digit reversal also appear with the other loop programs on loop programs in Java for ICSE Class 10, and the method-writing rules used above are on user-defined methods and overloading for ICSE Class 10.
Q5. How are special number programs taught live?
Students who memorise seventeen programs forget them by March. Students who own the template can write an eighteenth number they have never seen. The live classes are built round that second habit.
In the first class the digit loop is dry run on paper for two or three numbers until each student can fill a pass table without help.
At 5:30 PM IST the mentor gives a definition, sometimes one from the table above and sometimes an unfamiliar one, and the group writes the program from the template against a timer.
Answers are marked in front of everyone: the copy before the loop, the right starting values, the comparison, the comments and the variable table each earn their share.
At 8:00 PM IST the programs are run in BlueJ with 0, a single digit, a number with a zero inside and a number with leading zeros, so the weak spots show before the exam.
Each fortnight ends with a worksheet of unseen numbers; from December the same questions arrive inside full timed papers.
Number programs often sit inside a menu with two choices; that shape is covered on ICSE Class 10 menu driven programs. The full list of program families is on ICSE Class 10 Java programs for practice.
Batch or personalised: you choose
The definitions table, the template and the BlueJ test runs are identical in both formats. In India, families choose the fixed evening mini batch or a private slot; ICSE students abroad learn one to one. Billing is monthly with no admission fee.
Option 1 · Fixed batch timings
₹2,999
per month, two live classes a week
Option 2 · Choose your own timing
₹4,999
per month, one private class a weektwo private classes a week, at a time set with you
Outside India: the ICSE Computer Applications course runs as personalised one to one, two private classes a week at a time set in your own time zone. The mini batch is taught for families in India.
A student who confuses Niven with neon, or Armstrong with Disarium, often needs only a few one to one sessions with the definitions table and the template side by side. A student who wants steady weekly practice across every Section B family is better served by the two batch classes. Fees are shown in your own currency.
Studying outside India?
ICSE schools outside India sit the same Computer Applications paper, so the same digit loop decides the same Section B marks. Abroad, the practice runs one to one, after school in the student's own time zone.
| Where you live | Time difference | Usual class window, local time | Format |
|---|---|---|---|
| India (IST) every Indian city | IST | Tue 5:30 PM, Wed 8:00 PM | Mini batch or 1-on-1 |
| United Arab Emirates Dubai, Sharjah | 1 h 30 min behind India | 3:00 PM to 9:00 PM | Personalised 1-on-1 |
| Indonesia and Thailand West Java, Bangkok area | 1 h 30 min ahead of India | 3:30 PM to 9:00 PM | Personalised 1-on-1 |
| Singapore Singapore | 2 h 30 min ahead of India | 3:30 PM to 9:00 PM | Personalised 1-on-1 |
The slot is agreed after the free demo and moved around school tests. More on overseas classes is on ICSE Computer Applications classes in the Gulf and abroad.
What families say
Real reviews from real families. We neither write nor commission them.
★★★★★
"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."
Ria Mukherjee
Parent
★★★★★
"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."
Samriddha Mondal
Student
★★★★★
"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."
Vansh Agarwal
Student
★★★★★
"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."
Sonam Oswal
Parent of Dhairya
★★★★★
"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."
Sonu Goyal
Parent
★★★★★
"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."
Ritu Kedia
Parent
The rest of the Class 10 series
Every page in the ICSE Class 10 Computer Applications series, grouped by what you need: classes, each chapter, Section B programs, question practice, notes and revision, and the exam itself.
CBSE Class 10 AI (417): The Mon and Wed 9 PM AI batch CBSE AI 417 syllabus explained CBSE AI important questions Sample paper and mock tests
Questions about special numbers
A spy number is one whose digit sum equals its digit product. For 1124, the sum 1 + 1 + 2 + 4 is 8 and the product 1 x 1 x 2 x 4 is also 8, so it is a spy number. In Java, keep a sum starting at 0 and a product starting at 1, and fill both with the same digit loop.
A Niven number, also called a Harshad number, is divisible by the sum of its digits. 156 has digit sum 12, and 156 divided by 12 is exactly 13, so it is a Niven number. Find the digit sum with the template, then test n % sum == 0, making sure the number is above 0 first.
A duck number has at least one zero after its first non-zero digit, such as 4070 or 0703. Leading zeros alone do not count, so 0045 is not a duck number. Read the input as a String with next(), skip the leading zeros, then look for a zero in the rest with charAt.
Count the digits first and call the count k. Then use the digit loop to add each digit raised to the power k with (int) Math.pow(d, k). If the total equals the original number, it is an Armstrong number. 153 works with k = 3 and 1634 with k = 4.
A neon number equals the sum of the digits of its square. 9 squared is 81, and 8 + 1 is 9, so 9 is a neon number. Run the digit-sum loop on n * n and compare with n. Between 1 and 9999 the only neon numbers are 1 and 9.
Both repeat a step until a single value is reached. A magic number adds its digits again and again until one digit is left, and that digit must be 1, as in 199, 19, 10, 1. A happy number adds the squares of its digits each time, as in 19, 82, 68, 100, 1.
A perfect number equals the sum of its factors other than itself. 28 is perfect because 1 + 2 + 4 + 7 + 14 is 28; 6 and 496 are the other common examples. In Java, loop i from 1 to n minus 1, add i whenever n % i == 0, then compare the total with n.
Both raise digits to powers. An Armstrong number raises every digit to the same power, the number of digits, as in 153. A Disarium number raises each digit to its own position from the left, as in 135, which is 1 + 3 squared + 5 cubed.
No. Memorise the definitions and one template: take d = n % 10, use d, then n = n / 10, all on a copy of n. Every program on this page is that loop with one line changed. If the exam gives an unfamiliar number with its definition, the same template still works.
Number-property programs are a regular Section B shape, and the question normally states the definition it wants. We have not printed year tags here because we only tag a year after checking the real paper. Practise the template with all seventeen definitions and any of them is manageable.
Yes. In the mini batch on Tuesday and Wednesday evenings in India, students write a new number from the template each week, have it marked against the scheme on screen and then run it in BlueJ with edge cases. Families abroad, or who need another time, can take personalised one to one classes.
Start
In the free demo your child dry runs the digit template on one number, writes a full program for a second number from its definition, and then tests it in BlueJ with the mentor using awkward inputs. You hear honestly afterwards how secure the template is, and whether the mini batch or one to one fits better.
Want the broader picture first? See ICSE Computer Applications important questions or the ICSE Class 10 Java classes.
WhatsApp us · +91 91233 66161 · connect@modernagecoders.com
Every class is live video. The form requests a callback and reserves nothing.
A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.
Book a priority demo