Java

50 Important Java Programs for ICSE Class 10 Boards

The complete revision bank: seven program families the paper draws from, 50 programs, every one compiled, executed, and shown with its real output.

Modern Age Coders
Modern Age Coders July 4, 2026
24 min read
50 important Java programs for the ICSE Class 10 board exam with real outputs

Ask any ICSE Computer Applications teacher what separates a 95 from a 70, and you will hear the same answer: the students who score are the ones who have already written the standard programs so many times that the exam feels like revision. This page is that practice, in one place: 50 Java programs for ICSE Class 10, organised into the seven families the paper draws from.

Every single program below was compiled and executed before being published, and the output under each one is the real output it printed. Each uses sample values written directly into the code so you can run it the moment you paste it into BlueJ. Where an exam question says accept from the user, wrap the same logic in a Scanner, the logic is the mark-earning part.

If 50 feels like a lot, start with our Top 20 for ICSE, which walks the highest-frequency picks slowly with full explanations. This page is the complete bank: broader, faster, built for revision.

How the 50 Are Organised

In the ICSE paper, Section B carries 60 of the 100 marks and is where full programs are written, with a choice of questions. The seven families below are how those questions cluster, and knowing which family a question belongs to is half of solving it.

The 50 ICSE Java programs organised into seven families: conditions, loops and series, special numbers, patterns, strings, arrays, and methods with constructors
Seven families, 50 programs. Recognise the family and you already know the shape of the answer.
๐Ÿ’ก

The recognition habit

Before writing any exam answer, name the family out loud: this is a special number, so it is digit extraction plus one comparison. This is a pattern, so outer loop rows, inner loop columns. Students who classify first almost never freeze.

Conditions and Operators

Eight warm-up programs built on if, else, and the operators. Section A loves these as output questions, and Section B uses them as the opening steps of bigger programs.

1. Even or odd

Question: Write a program to check whether a number is even or odd.

public class EvenOdd {
    public static void main(String[] args) {
        int n = 47;
        if (n % 2 == 0)
            System.out.println(n + " is even");
        else
            System.out.println(n + " is odd");
    }
}
47 is odd

2. Largest of three numbers

Question: Write a program to find the largest of three numbers using nested if.

public class LargestOfThree {
    public static void main(String[] args) {
        int a = 25, b = 62, c = 41;
        int largest;
        if (a > b && a > c)
            largest = a;
        else if (b > c)
            largest = b;
        else
            largest = c;
        System.out.println("Largest = " + largest);
    }
}
Largest = 62

3. Positive, negative or zero

Question: Write a program to check whether a number is positive, negative, or zero.

public class PosNegZero {
    public static void main(String[] args) {
        int n = -18;
        if (n > 0)
            System.out.println("Positive");
        else if (n < 0)
            System.out.println("Negative");
        else
            System.out.println("Zero");
    }
}
Negative

4. Leap year check

Question: Write a program to check whether a year is a leap year.

public class LeapYear {
    public static void main(String[] args) {
        int year = 2028;
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
            System.out.println(year + " is a leap year");
        else
            System.out.println(year + " is not a leap year");
    }
}
2028 is a leap year

5. Grade from marks (if-else ladder)

Question: Write a program to print the grade for given marks: A for 80 and above, B for 60 to 79, C for 40 to 59, else D.

public class GradeCalc {
    public static void main(String[] args) {
        int marks = 73;
        char grade;
        if (marks >= 80)
            grade = 'A';
        else if (marks >= 60)
            grade = 'B';
        else if (marks >= 40)
            grade = 'C';
        else
            grade = 'D';
        System.out.println("Marks " + marks + " gets grade " + grade);
    }
}
Marks 73 gets grade B

6. Simple interest

Question: Write a program to calculate simple interest for a given principal, rate, and time.

public class SimpleInterest {
    public static void main(String[] args) {
        double p = 5000, r = 8, t = 2;
        double si = (p * r * t) / 100;
        System.out.println("Simple Interest = " + si);
    }
}
Simple Interest = 800.0

7. Celsius to Fahrenheit

Question: Write a program to convert a temperature from Celsius to Fahrenheit.

public class CelsiusFahrenheit {
    public static void main(String[] args) {
        double c = 37.0;
        double f = c * 9 / 5 + 32;
        System.out.println(c + " C = " + f + " F");
    }
}
37.0 C = 98.6 F

8. Buzz number

Question: Write a program to check whether a number is a Buzz number. A buzz number ends with 7 or is divisible by 7.

public class BuzzNumber {
    public static void main(String[] args) {
        int n = 63;
        if (n % 10 == 7 || n % 7 == 0)
            System.out.println(n + " is a Buzz number");
        else
            System.out.println(n + " is not a Buzz number");
    }
}
63 is a Buzz number

Loops and Series

The while and for loop workhorses. Master the digit-extraction pair here, sum of digits and reverse, because half the special numbers below reuse it.

9. Sum of first n natural numbers

Question: Write a program to find the sum of the first n natural numbers.

public class SumNatural {
    public static void main(String[] args) {
        int n = 50, sum = 0;
        for (int i = 1; i <= n; i++)
            sum = sum + i;
        System.out.println("Sum of first " + n + " numbers = " + sum);
    }
}
Sum of first 50 numbers = 1275

10. Factorial of a number

Question: Write a program to find the factorial of a number using a loop.

public class Factorial {
    public static void main(String[] args) {
        int n = 7;
        long fact = 1;
        for (int i = 1; i <= n; i++)
            fact = fact * i;
        System.out.println(n + "! = " + fact);
    }
}
7! = 5040

11. Multiplication table

Question: Write a program to print the multiplication table of a number.

public class MultTable {
    public static void main(String[] args) {
        int n = 7;
        for (int i = 1; i <= 10; i++)
            System.out.println(n + " x " + i + " = " + (n * i));
    }
}
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70

12. Fibonacci series

Question: Write a program to print the first n terms of the Fibonacci series.

public class Fibonacci {
    public static void main(String[] args) {
        int n = 10, a = 0, b = 1;
        for (int i = 1; i <= n; i++) {
            System.out.print(a + " ");
            int c = a + b;
            a = b;
            b = c;
        }
        System.out.println();
    }
}
0 1 1 2 3 5 8 13 21 34

13. Sum of the series 1 + 1/2 + 1/3 + ...

Question: Write a program to find the sum of the series 1 + 1/2 + 1/3 + ... + 1/n.

public class SeriesSum {
    public static void main(String[] args) {
        int n = 5;
        double sum = 0;
        for (int i = 1; i <= n; i++)
            sum = sum + 1.0 / i;
        System.out.println("Sum = " + sum);
    }
}
Sum = 2.283333333333333

14. Sum of digits

Question: Write a program to find the sum of the digits of a number.

public class DigitSum {
    public static void main(String[] args) {
        int n = 4718, sum = 0, temp = n;
        while (temp != 0) {
            sum = sum + temp % 10;
            temp = temp / 10;
        }
        System.out.println("Sum of digits of " + n + " = " + sum);
    }
}
Sum of digits of 4718 = 20

15. Reverse a number

Question: Write a program to reverse the digits of a number.

public class ReverseNumber {
    public static void main(String[] args) {
        int n = 8256, rev = 0, temp = n;
        while (temp != 0) {
            rev = rev * 10 + temp % 10;
            temp = temp / 10;
        }
        System.out.println("Reverse of " + n + " = " + rev);
    }
}
Reverse of 8256 = 6528

16. Count the digits

Question: Write a program to count how many digits a number has.

public class CountDigits {
    public static void main(String[] args) {
        int n = 90387, count = 0, temp = n;
        while (temp != 0) {
            count++;
            temp = temp / 10;
        }
        System.out.println(n + " has " + count + " digits");
    }
}
90387 has 5 digits

Special Numbers

The most ICSE family of them all. Ten number types, each with a one-line definition and a worked check. Notice how nearly all of them are digit extraction wearing different hats.

How to recognise which family an ICSE Java question belongs to from its wording
Question words that give the family away. Classify first, then write.

17. Prime number

Question: Write a program to check whether a number is prime.

public class PrimeCheck {
    public static void main(String[] args) {
        int n = 97, count = 0;
        for (int i = 1; i <= n; i++) {
            if (n % i == 0)
                count++;
        }
        if (count == 2)
            System.out.println(n + " is prime");
        else
            System.out.println(n + " is not prime");
    }
}
97 is prime

18. Palindrome number

Question: Write a program to check whether a number is a palindrome.

public class PalindromeNum {
    public static void main(String[] args) {
        int n = 1331, rev = 0, temp = n;
        while (temp != 0) {
            rev = rev * 10 + temp % 10;
            temp = temp / 10;
        }
        if (rev == n)
            System.out.println(n + " is a palindrome");
        else
            System.out.println(n + " is not a palindrome");
    }
}
1331 is a palindrome

19. Armstrong number

Question: Write a program to check whether a 3-digit number is an Armstrong number.

public class Armstrong {
    public static void main(String[] args) {
        int n = 371, sum = 0, temp = n;
        while (temp != 0) {
            int d = temp % 10;
            sum = sum + d * d * d;
            temp = temp / 10;
        }
        if (sum == n)
            System.out.println(n + " is an Armstrong number");
        else
            System.out.println(n + " is not an Armstrong number");
    }
}
371 is an Armstrong number

20. Perfect number

Question: Write a program to check whether a number is a Perfect number.

public class PerfectNum {
    public static void main(String[] args) {
        int n = 496, sum = 0;
        for (int i = 1; i < n; i++) {
            if (n % i == 0)
                sum = sum + i;
        }
        if (sum == n)
            System.out.println(n + " is a Perfect number");
        else
            System.out.println(n + " is not a Perfect number");
    }
}
496 is a Perfect number

21. Automorphic number

Question: Write a program to check whether a number is Automorphic. Its square must end with the number itself.

public class Automorphic {
    public static void main(String[] args) {
        int n = 76;
        int sq = n * n;
        String s1 = Integer.toString(n);
        String s2 = Integer.toString(sq);
        if (s2.endsWith(s1))
            System.out.println(n + " is Automorphic (square = " + sq + ")");
        else
            System.out.println(n + " is not Automorphic");
    }
}
76 is Automorphic (square = 5776)

22. Neon number

Question: Write a program to check whether a number is a Neon number. The digits of its square must add up to the number.

public class NeonNum {
    public static void main(String[] args) {
        int n = 9, sq = n * n, sum = 0;
        while (sq != 0) {
            sum = sum + sq % 10;
            sq = sq / 10;
        }
        if (sum == n)
            System.out.println(n + " is a Neon number");
        else
            System.out.println(n + " is not a Neon number");
    }
}
9 is a Neon number

23. Spy number

Question: Write a program to check whether a number is a Spy number. The sum of its digits must equal the product of its digits.

public class SpyNum {
    public static void main(String[] args) {
        int n = 1412, sum = 0, product = 1, temp = n;
        while (temp != 0) {
            int d = temp % 10;
            sum = sum + d;
            product = product * d;
            temp = temp / 10;
        }
        if (sum == product)
            System.out.println(n + " is a Spy number");
        else
            System.out.println(n + " is not a Spy number");
    }
}
1412 is a Spy number

24. Disarium number

Question: Write a program to check whether a number is a Disarium number. Digits raised to their positions must add up to the number.

public class Disarium {
    public static void main(String[] args) {
        int n = 175;
        int len = Integer.toString(n).length();
        int sum = 0, temp = n;
        while (temp != 0) {
            int d = temp % 10;
            sum = sum + (int) Math.pow(d, len);
            len--;
            temp = temp / 10;
        }
        if (sum == n)
            System.out.println(n + " is a Disarium number");
        else
            System.out.println(n + " is not a Disarium number");
    }
}
175 is a Disarium number

25. Kaprekar number

Question: Write a program to check whether a number is a Kaprekar number. Split its square so the parts add back to the number.

public class Kaprekar {
    public static void main(String[] args) {
        int n = 45;
        int sq = n * n;
        String s = Integer.toString(sq);
        int digits = Integer.toString(n).length();
        String left = s.substring(0, s.length() - digits);
        String right = s.substring(s.length() - digits);
        int leftVal = left.isEmpty() ? 0 : Integer.parseInt(left);
        int rightVal = Integer.parseInt(right);
        if (leftVal + rightVal == n)
            System.out.println(n + " is a Kaprekar number (" + leftVal + " + " + rightVal + ")");
        else
            System.out.println(n + " is not a Kaprekar number");
    }
}
45 is a Kaprekar number (20 + 25)

26. Harshad number

Question: Write a program to check whether a number is a Harshad number. It must be divisible by the sum of its digits.

public class Harshad {
    public static void main(String[] args) {
        int n = 108, sum = 0, temp = n;
        while (temp != 0) {
            sum = sum + temp % 10;
            temp = temp / 10;
        }
        if (n % sum == 0)
            System.out.println(n + " is a Harshad number");
        else
            System.out.println(n + " is not a Harshad number");
    }
}
108 is a Harshad number

Patterns with Nested Loops

One pattern appears in almost every paper. The outer loop counts rows, the inner loop decides what each row holds. Six shapes cover every variant examiners rotate through.

27. Right triangle of stars

Question: Write a program to print a right-angled triangle of stars with 5 rows.

public class StarTriangle {
    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= i; j++)
                System.out.print("* ");
            System.out.println();
        }
    }
}
*
* *
* * *
* * * *
* * * * *

28. Inverted star triangle

Question: Write a program to print an inverted right-angled triangle of stars.

public class InvTriangle {
    public static void main(String[] args) {
        for (int i = 5; i >= 1; i--) {
            for (int j = 1; j <= i; j++)
                System.out.print("* ");
            System.out.println();
        }
    }
}
* * * * *
* * * *
* * *
* *
*

29. Star pyramid

Question: Write a program to print a centred pyramid of stars with 5 rows.

public class Pyramid {
    public static void main(String[] args) {
        int n = 5;
        for (int i = 1; i <= n; i++) {
            for (int s = 1; s <= n - i; s++)
                System.out.print(" ");
            for (int j = 1; j <= 2 * i - 1; j++)
                System.out.print("*");
            System.out.println();
        }
    }
}
    *
   ***
  *****
 *******
*********

30. Number triangle

Question: Write a program to print a triangle where row i contains the numbers 1 to i.

public class NumTriangle {
    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= i; j++)
                System.out.print(j + " ");
            System.out.println();
        }
    }
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

31. Floyd's triangle

Question: Write a program to print Floyd's triangle with 4 rows.

public class FloydTriangle {
    public static void main(String[] args) {
        int num = 1;
        for (int i = 1; i <= 4; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(num + " ");
                num++;
            }
            System.out.println();
        }
    }
}
1
2 3
4 5 6
7 8 9 10

32. Alphabet pattern

Question: Write a program to print a triangle where row i contains the first i capital letters.

public class CharPattern {
    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++) {
            for (int j = 0; j < i; j++)
                System.out.print((char) (65 + j) + " ");
            System.out.println();
        }
    }
}
A
A B
A B C
A B C D
A B C D E

String Programs

String questions carry heavy marks and reward method knowledge: charAt, substring, split, and the Character checks. Piglatin and initials are perennial board favourites.

33. Count vowels

Question: Write a program to count the vowels in a string.

public class CountVowels {
    public static void main(String[] args) {
        String s = "Computer Applications";
        int count = 0;
        String lower = s.toLowerCase();
        for (int i = 0; i < lower.length(); i++) {
            char ch = lower.charAt(i);
            if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
                count++;
        }
        System.out.println("Vowels = " + count);
    }
}
Vowels = 8

34. Reverse a string

Question: Write a program to reverse a string using a loop.

public class ReverseString {
    public static void main(String[] args) {
        String s = "BLUEJ";
        String rev = "";
        for (int i = s.length() - 1; i >= 0; i--)
            rev = rev + s.charAt(i);
        System.out.println("Reverse of " + s + " is " + rev);
    }
}
Reverse of BLUEJ is JEULB

35. Palindrome string

Question: Write a program to check whether a word is a palindrome, ignoring case.

public class PalinString {
    public static void main(String[] args) {
        String s = "Madam";
        String rev = "";
        for (int i = s.length() - 1; i >= 0; i--)
            rev = rev + s.charAt(i);
        if (s.equalsIgnoreCase(rev))
            System.out.println(s + " is a palindrome");
        else
            System.out.println(s + " is not a palindrome");
    }
}
Madam is a palindrome

36. Toggle the case

Question: Write a program to change every uppercase letter to lowercase and vice versa.

public class ToggleCase {
    public static void main(String[] args) {
        String s = "IcSe BoArDs";
        String result = "";
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (Character.isUpperCase(ch))
                result = result + Character.toLowerCase(ch);
            else if (Character.isLowerCase(ch))
                result = result + Character.toUpperCase(ch);
            else
                result = result + ch;
        }
        System.out.println(result);
    }
}
iCsE bOaRdS

37. Count words

Question: Write a program to count the words in a sentence.

public class CountWords {
    public static void main(String[] args) {
        String s = "Practice one program every single day";
        String[] words = s.trim().split("\\s+");
        System.out.println("Words = " + words.length);
    }
}
Words = 6

38. Initials of a name

Question: Write a program to print the initials of a name followed by the surname, like S. K. Gupta.

public class Initials {
    public static void main(String[] args) {
        String name = "Sarojini Kavita Gupta";
        String[] parts = name.split(" ");
        String result = "";
        for (int i = 0; i < parts.length - 1; i++)
            result = result + parts[i].charAt(0) + ". ";
        result = result + parts[parts.length - 1];
        System.out.println(result);
    }
}
S. K. Gupta

39. Frequency of a character

Question: Write a program to count how many times a given character appears in a string.

public class CharFrequency {
    public static void main(String[] args) {
        String s = "programming";
        char target = 'm';
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == target)
                count++;
        }
        System.out.println("'" + target + "' appears " + count + " times");
    }
}
'm' appears 2 times

40. Piglatin form

Question: Write a program to convert a word into its Piglatin form: move letters up to the first vowel to the end and add AY.

public class PigLatin {
    public static void main(String[] args) {
        String s = "LONDON";
        int pos = -1;
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
                pos = i;
                break;
            }
        }
        String pig = s.substring(pos) + s.substring(0, pos) + "AY";
        System.out.println(s + " -> " + pig);
    }
}
LONDON -> ONDONLAY

Array Programs

Single dimensional arrays: search it, sort it, sum it. Bubble and selection sort plus both searches are explicitly on the syllabus, so all four live here.

A five week plan to practise all 50 ICSE Java programs before the board exam
Ten programs a week is a calm pace. Week six is for rewriting the ones that fought back.

41. Largest and smallest

Question: Write a program to find the largest and smallest element in an array.

public class MaxMin {
    public static void main(String[] args) {
        int[] arr = {34, 78, 12, 95, 41};
        int max = arr[0], min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) max = arr[i];
            if (arr[i] < min) min = arr[i];
        }
        System.out.println("Largest = " + max);
        System.out.println("Smallest = " + min);
    }
}
Largest = 95
Smallest = 12

42. Sum and average

Question: Write a program to find the sum and average of the elements of an array.

public class SumAverage {
    public static void main(String[] args) {
        int[] marks = {78, 85, 92, 66, 74};
        int sum = 0;
        for (int i = 0; i < marks.length; i++)
            sum = sum + marks[i];
        double avg = (double) sum / marks.length;
        System.out.println("Sum = " + sum);
        System.out.println("Average = " + avg);
    }
}
Sum = 395
Average = 79.0

43. Linear search

Question: Write a program to search for a value in an array using linear search.

public class LinearSearch {
    public static void main(String[] args) {
        int[] arr = {15, 8, 22, 39, 4};
        int key = 39, pos = -1;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == key) {
                pos = i;
                break;
            }
        }
        if (pos == -1)
            System.out.println(key + " not found");
        else
            System.out.println(key + " found at index " + pos);
    }
}
39 found at index 3

44. Binary search

Question: Write a program to search a sorted array using binary search.

public class BinarySearch {
    public static void main(String[] args) {
        int[] arr = {4, 11, 25, 38, 52, 67};
        int key = 38, low = 0, high = arr.length - 1, pos = -1;
        while (low <= high) {
            int mid = (low + high) / 2;
            if (arr[mid] == key) {
                pos = mid;
                break;
            } else if (arr[mid] < key)
                low = mid + 1;
            else
                high = mid - 1;
        }
        System.out.println(key + " found at index " + pos);
    }
}
38 found at index 3

45. Bubble sort

Question: Write a program to sort an array in ascending order using bubble sort.

import java.util.Arrays;
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {64, 25, 12, 89, 33};
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int t = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = t;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
[12, 25, 33, 64, 89]

46. Selection sort

Question: Write a program to sort an array in ascending order using selection sort.

import java.util.Arrays;
public class SelectionSort {
    public static void main(String[] args) {
        int[] arr = {29, 10, 44, 3, 18};
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[minIndex])
                    minIndex = j;
            }
            int t = arr[i];
            arr[i] = arr[minIndex];
            arr[minIndex] = t;
        }
        System.out.println(Arrays.toString(arr));
    }
}
[3, 10, 18, 29, 44]

47. Reverse an array

Question: Write a program to print the elements of an array in reverse order.

public class ReverseArray {
    public static void main(String[] args) {
        int[] arr = {2, 4, 6, 8, 10};
        for (int i = arr.length - 1; i >= 0; i--)
            System.out.print(arr[i] + " ");
        System.out.println();
    }
}
10 8 6 4 2

Methods, Constructors, and Menus

The paper always tests whether you can shape code, not just write it: overloaded methods, a class with a constructor, and the switch statement.

48. Overloaded area() methods

Question: Write overloaded methods area() to compute the area of a circle, a rectangle, and a triangle, and call all three.

public class AreaOverload {
    static double area(double radius) {
        return 3.14 * radius * radius;
    }
    static double area(double length, double breadth) {
        return length * breadth;
    }
    static double area(double base, double height, boolean isTriangle) {
        return 0.5 * base * height;
    }
    public static void main(String[] args) {
        System.out.println("Circle    = " + area(7));
        System.out.println("Rectangle = " + area(12, 5));
        System.out.println("Triangle  = " + area(10, 8, true));
    }
}
Circle    = 153.86
Rectangle = 60.0
Triangle  = 40.0

49. A class with a constructor

Question: Define a class Student with a parameterised constructor that stores a name and marks, and a method to display them. Create two objects.

public class StudentCtor {
    String name;
    int marks;
    StudentCtor(String n, int m) {
        name = n;
        marks = m;
    }
    void display() {
        System.out.println(name + " scored " + marks);
    }
    public static void main(String[] args) {
        StudentCtor s1 = new StudentCtor("Asha", 92);
        StudentCtor s2 = new StudentCtor("Rohan", 85);
        s1.display();
        s2.display();
    }
}
Asha scored 92
Rohan scored 85

50. Menu with switch

Question: Write a menu-driven program using switch to print whether a stored choice selects square or cube of a number.

public class MenuSwitch {
    public static void main(String[] args) {
        int choice = 2, n = 6;
        switch (choice) {
            case 1:
                System.out.println("Square of " + n + " = " + (n * n));
                break;
            case 2:
                System.out.println("Cube of " + n + " = " + (n * n * n));
                break;
            default:
                System.out.println("Invalid choice");
        }
    }
}
Cube of 6 = 216

Turning Sample Values into User Input

Every program above uses fixed sample values so it runs instantly. When the question demands input, the swap is mechanical: import java.util.Scanner, create one, and replace the assignment.

import java.util.Scanner;

// instead of:  int n = 47;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();          // everything after this line stays identical

That is the entire difference. Practise the logic with fixed values, and add the Scanner shell in the exam when the wording asks for it.

The Marks You Lose Without Noticing

  • Forgetting to reset before reuse: if you reverse a number and then need it again, keep the original in a temp variable. Half of all special-number bugs are this.
  • Integer division surprises: sum / count truncates when both are int. Cast one side to double for averages.
  • Comparing strings with ==: use equals() or equalsIgnoreCase(). The == operator compares references, not text.
  • Off-by-one in loops: arrays run 0 to length - 1. Writing i <= arr.length throws ArrayIndexOutOfBoundsException.
  • Missing break in switch: without it, every case below the match also runs.
โœ…

The examiner's eye

Presentation earns quiet marks: meaningful variable names, consistent indentation, and one comment naming the logic. Two programs with identical logic do not always score identically.


Frequently Asked Questions

They cover every program family the Computer Applications paper draws from: conditions, loops, special numbers, patterns, strings, arrays, and methods with constructors. Pair them with past-paper output questions and theory revision, and the program-writing side is fully prepared.

Special numbers (Armstrong, palindrome, prime, automorphic, spy, and their cousins), one nested-loop pattern, one or two string programs like Piglatin or initials, and an array program such as bubble sort or binary search appear again and again across years.

So every program runs the moment you paste it into BlueJ, and so the output shown could be captured from a real execution. Converting any of them to user input is a three-line Scanner change, shown in the section above.

Ten a week for five weeks, typing each one rather than reading it, then a final week rewriting from memory the ones that resisted. Classify every program by family as you go; recognition is what the exam actually tests.

The Top 20 walks the highest-frequency programs slowly, with step-by-step explanations and Scanner-based input. This page is the full revision bank: 50 programs, faster pace, sample values, built for the weeks before the exam.

Learn the definitions, not the code. Every special number program is digit extraction plus one comparison, so once you can write the extraction loop from memory, each definition takes only a line or two more.

Bubble sort and selection sort for sorting, linear search and binary search for searching, all on single dimensional arrays. All four are in the array family above, executed with their outputs.

Fifty Programs, One Calm Exam Hall

There is nothing mysterious about a strong Computer Applications score. It is the same seven families, practised until the pen moves on its own. Work the bank, use the Top 20 walkthroughs when a family needs slower treatment, and keep our string handling guide beside the string family, since that is where the richest marks hide.

And if you want a teacher who has coached this exact paper, our Java classes for ICSE students run live, with learners aged 6 to 67 across our courses. A free demo is the fastest way to see the difference feedback makes.

Related reading

Modern Age Coders

About Modern Age Coders

Expert educators passionate about making coding accessible and fun for learners of all ages.

Ask Misti AI
Chat with us