ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2025 ICSE Computer Science Paper



Share with a Friend

Solved 2025 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

SUPERSPY Program - ICSE 2025 Computer Science

Question 7
Define a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.


Example 1:
Input: 1021
Output: SUPERSPY number [SUM OF THE DIGITS = 1 + 0 + 2 + 1 = 4, NUMBER OF DIGITS = 4]


Example 2:
Input: 125
Output: Not a SUPERSPY number [1 + 2 + 5 is not equal to 3]

import java.util.Scanner; class SuperSpy{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("Enter the number: "); int num = Integer.parseInt(in.nextLine()); int sum = 0; int count = 0; for(int i = num; i != 0; i /= 10){ count++; sum += i % 10; } if(sum == count) System.out.println(num + " is a superspy number!"); else System.out.println(num + " is not a superspy number."); } }

Output

 
OUTPUT 1:
Enter the number: 1021
1021 is a superspy number!

OUTPUT 2:
Enter the number: 125
125 is not a superspy number.