ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2014 ICSE Computer Science Paper



Share with a Friend

Solved 2014 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Special Two Digit Number Program - ICSE 2014 Computer Science

A special two-digit number is such that when the sum of its digits is added to the product of its digits, the result is equal to the original two-digit number.
Example:
Consider the number 59.
Sum of digits = 5 + 9 = 14.
Product of its digits = 5 × 9 = 45.
Sum of the sum of digits and product of digits = 14 + 45 = 59.

Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value is equal to the number input, output the message “Special 2-digit number” otherwise, output the message “Not a special 2-digit number”.

import java.util.Scanner; class Special{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("Enter the number: "); int num = Integer.parseInt(in.nextLine()); if(num > 99 || num < 10){ System.out.println("Not a special 2-digit number"); return; } int first = num / 10; int last = num % 10; int sum = first + last; int product = first * last; if(num == sum + product) System.out.println("Special 2-digit number"); else System.out.println("Not a special 2-digit number"); } }

Output

 
 OUTPUT 1: 
Enter the number: 59
Special 2-digit number