- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Conditional Constructs in Java
Chapter 9
Conditional Constructs in Java
Class 9 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Programs - Special Two-Digit Number
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 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 input number, display the message "Special 2 - digit number" otherwise, display the message "Not a special two-digit number".
import java.util.Scanner;
public class SpecialTwoDigitNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a two-digit number: ");
int num = sc.nextInt();
// Extract digits
int tens = num / 10;
int units = num % 10;
// Calculate sum and product of digits
int sum = tens + units;
int product = tens * units;
// Check special condition
if (sum + product == num) {
System.out.println("Special 2-digit number");
} else {
System.out.println("Not a special two-digit number");
}
sc.close();
}
}
Output
Output 1 :
SAMPLE INPUT : Enter a two-digit number: 59 SAMPLE OUTPUT : Special 2-digit numberOutput 2 :
SAMPLE INPUT : Enter a two-digit number: 23 SAMPLE OUTPUT : Not a special two-digit number
Explanation
1. Input
- The program accepts a two-digit number from the user.
2. Digit Extraction
int tens = num / 10;
int units = num % 10;
- Tens digit is obtained using division.
- Units digit is obtained using modulus operator.
3. Sum & Product Calculation
int sum = tens + units;
int product = tens * units;
4. Special Number Check
if (sum + product == num)
- If (sum of digits + product of digits) equals the original number, it is a special two-digit number.
