-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram20.java
More file actions
31 lines (28 loc) · 1.02 KB
/
Program20.java
File metadata and controls
31 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Program 20
// Week 1 - Day 4
// Consider an n digit number k. square it and add the right n digits to the left n and n-1 digits. if the resultant sum is k then k is called a kaprekar number.
// For example , 9 is a kaprekar number since 9^2 = 81 and 8+1 = 9. Similarly, 297 is a kaprekar number since 297^2 = 88209 and 88+209 = 297.
// Input Format: input consist of a single integer.
import java.util.*;
public class Program20 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int count = 0;
int sq = num * num;
int temp = num;
while(num !=0){
num /= 10;
count++;
}
int power = (int)Math.pow(10, count);
int right = sq % power;
int left = sq / power;
int sum = left + right;
if(sum == temp){
System.out.println(temp + " is a Kaprekar number.");
}else{
System.out.println(temp + " is not a Kaprekar number.");
}
}
}