ICSE Class 10 · Computer Applications (Java) · Special number programs 2027

Special number programs in Java for ICSE, built on one template.

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

Courses where number programs are taught

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.

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?

Special numbers in Java ICSE: seventeen definitions in one table

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.

NumberRule in one sentenceExample, checkedWhat changes in the template
SpySum of digits equals product of digits1124: 1+1+2+4 = 8 = 1x1x2x4Keep a sum and a product
Niven (Harshad)Divisible by the sum of its digits156: sum 12, 156 / 12 = 13Sum, then n % sum == 0
NeonSum of the digits of its square equals the number9: 81, 8+1 = 9Run the loop on n * n
ArmstrongSum of each digit raised to the number of digits equals the number153 = 1+125+27; 1634Count digits first, add Math.pow(d, k)
DuckHas a zero somewhere after its first non-zero digit4070 yes; 0045 noRead as a String, test charAt
MagicAdding the digits again and again ends at 1199, 19, 10, 1Repeat the sum while the result is above 9
PerfectSum of its factors below itself equals the number28 = 1+2+4+7+14No digits: loop over factors
AutomorphicIts square ends in the number itself76: 5776Compare n * n % 10k with n
DisariumSum of each digit raised to its position from the left equals the number135 = 1+9+125Power k, then k-- each pass
Special (Krishnamurthy)Sum of the factorials of its digits equals the number145 = 1!+4!+5!Add fact(d)
BuzzDivisible by 7 or ends in 749 and 107No loop: n % 7 and n % 10
PronicProduct of two consecutive integers56 = 7x8Loop i while i * (i + 1) <= n
SunnyThe next number, n + 1, is a perfect square80: 81 = 9x9Math.sqrt(n + 1) has no fraction
TechEven digit count; square of the sum of its two halves equals the number2025: (20+25)2Split with / and % by 10k/2
HappyReplacing it by the sum of the squares of its digits, again and again, ends at 119, 82, 68, 100, 1Add d * d, repeat
Palindrome numberReads the same reversed12321Build rev = rev * 10 + d
Twisted primePrime, and still prime with its digits reversed13 and 31Reverse, 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?

The digit-extraction template every number program uses

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.

The templatethree lines in a loop
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.

Passd = t % 10sumproductt after
startnone011124
1444112
226811
31781
41880, 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.

Copy before the loop

The loop destroys t. If you loop on n itself, the final sum == n compares against 0 and every answer is wrong.

Right digit first

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.

Guard the zero

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 number program ICSE, duck number, 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.

Armstrong number for any number of digits

ArmstrongN.javapower = number of digits
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.

VariableTypePurpose
nintthe number entered
kintnumber of digits
tintworking copy of n
dintthe last digit
sumintsum of d to the power k
Sample runsJava 21
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.

Duck number, read as a String

Duck.javaleading zeros do not count
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.

VariableTypePurpose
sStringthe number as typed
iintindex of the first non-zero digit
jintloop counter after that digit
duckbooleantrue once a later zero is found
Sample runsJava 21
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.

Magic and perfect numbers in one program

MagicPerfect.javarepeated sum, factor sum
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.

VariableTypePurpose
nintthe number entered
mintrepeated digit sum
sintdigit sum of one round
fintsum of factors below n
iintpossible factor
Sample runsJava 21
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.

Special and Disarium numbers: two sums in one pass

SpecialDisarium.javafactorials and positions
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.

VariableTypePurpose
nintthe number entered
kintposition of the current digit
t, dintworking copy, last digit
sfintsum of digit factorials
spintsum of positional powers
f, iintfactorial and its counter, in fact()
Sample runsJava 21
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?

Template first, then a new number every week

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.

  1. The template, traced by hand

    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.

  2. A new number every Tuesday

    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.

  3. Marked against the scheme on screen

    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.

  4. Run with edge cases on Wednesday

    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.

  5. Worksheets, doubt time and mock papers

    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

Learn number programs in the mini batch, or one to one

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

Mini batch, Tuesday 5:30 PM and Wednesday 8 PM

₹2,999

per month, two live classes a week

  • Tuesday 5:30 PM and Wednesday 8:00 PM IST, live
  • No more than six ICSE Class 10 students
  • A new special number written from the template weekly
  • Answers marked against the scheme on screen
  • Edge cases run in BlueJ before the exam finds them
Book a free demo in this batch

Option 2 · Choose your own timing

Personalised one to one

₹4,999

per month, one private class a week, at a time set with you

  • A slot the family chooses, in India or abroad
  • Time spent on the numbers your child mixes up
  • Pass tables traced together until they are automatic
  • Unseen definitions once the template is secure
  • The same mentors and the same 2027 syllabus
Ask for a personalised plan

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?

Number program practice for ICSE students abroad

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 liveTime differenceUsual class window, local timeFormat
India (IST)
every Indian city
ISTTue 5:30 PM, Wed 8:00 PMMini batch or 1-on-1
United Arab Emirates
Dubai, Sharjah
1 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Indonesia and Thailand
West Java, Bangkok area
1 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1
Singapore
Singapore
2 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 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

Rated 4.9 across 547 Google reviews

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

More pages for Class 10 board students

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

What students ask about special number programs in Java

What is a spy number in Java?

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.

What is a Niven number in Java?

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.

What is a duck number in ICSE?

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.

How do you write an Armstrong number program for ICSE?

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.

What is a neon number?

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.

What is the difference between a magic number and a happy number?

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.

What is a perfect number in Java?

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.

What is the difference between Armstrong and Disarium numbers?

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.

Do I have to memorise every special number program?

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.

Which special number programs come in the ICSE board exam?

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.

Do you teach special number programs in live classes?

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

Try a free live number programs class

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.

We call within a few hours. No card, no enrolment fee.

Want it sooner? Book a priority demo

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

Keep exploring Modern Age Coders

By class and age

Learn more

Free resources

From the blog

Start here