-
Notifications
You must be signed in to change notification settings - Fork 0
/
kaprekar.java
59 lines (55 loc) · 1.05 KB
/
kaprekar.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Input -> 4
45
13
1
9
Output -> 1
0
1
1
*/
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int t=scan.nextInt();
while(t!=0)
{
int n=scan.nextInt();
int mul=1,sum=0;
mul=n*n;
if(n>=0 && n<=9)
{
int second=mul%10;
int first=mul/10;
sum=first+second;
}
else if(n>=10 && n<=99)
{
int second=mul%100;
int first=mul/100;
sum=first+second;
}
else if(n>=100 && n<=999)
{
int second=mul%1000;
int first=mul/1000;
sum=first+second;
}
else
{
int second=mul%10000;
int first=mul/10000;
sum=first+second;
}
if(sum==n)
System.out.println("1");
else
System.out.println("0");
t--;
}
}
}