Kaprekar Number Check in Java: Explanation & Practice
Check if a number is a Kaprekar number
Problem summary
A Kaprekar number's square can be split into two parts that add up to the original (e.g., 45² = 2025, 20+25 = 45).
Starter code
public class Main {
public static void main(String[] args) {
int number = 45; // Test case 1
// Check if Kaprekar
// Print: Is Kaprekar: <true/false>
}
}Expected output and test cases
- 45² = 2025, 20+25=45
Is Kaprekar: true
- 9² = 81, 8+1=9
Is Kaprekar: true
- 10 is not Kaprekar
Is Kaprekar: false
Hints
- Calculate square of number
- Try splitting at different positions
- Right part cannot be 0
Related Control Flow exercises
- Practice Digital Root in Java
- Practice Abundant Number Check in Java
- Practice Neon Number Check in Java
Practice all Control Flow exercises · Run this idea in the Java compiler