public static void meth(int n) {
int temp, k, a = 0, r, rem, quo;
temp = n;
k = n * n;
while (n > 0) {
r = n % 10;
a++;
n = n / 10;
}
rem = k % ((int) Math.pow(10, a));
quo = k / ((int) Math.pow(10, a));
if ((rem + quo) == temp)
System.out.println("kaprekar number");
else
System.out.println(" not kaprekar number");
}
public static void main(String ar[]) {
meth(45);
}
}
Output:
45 is karprekar number because 45 squre = 2025 = 20+25
like this we can check whether the given number is karpreker number or not.
No comments:
Post a Comment