File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ import java .io .*;
3
+
4
+ class Main {
5
+
6
+ public static int count =0 ;
7
+
8
+ public static int KaprekarsConstant (int num ) {
9
+
10
+ String other =Integer .toString (num );
11
+ int []arr =new int [other .length ()];
12
+
13
+ for (int i =0 ;i <other .length ();i ++){
14
+ arr [i ]=other .charAt (i )-'0' ;
15
+ }
16
+ Arrays .sort (arr );
17
+
18
+ String low ="" ;
19
+ for (int i =0 ;i <arr .length ;i ++){
20
+ low +=arr [i ];
21
+ }
22
+
23
+ String high =new StringBuilder (low ).reverse ().toString ();
24
+ int diff =Integer .parseInt (high )-Integer .parseInt (low );
25
+
26
+ if (diff <1000 ){
27
+ diff =Integer .parseInt (Integer .toString (diff )+"0" );
28
+ }
29
+ count ++;
30
+ return diff !=6174 ? KaprekarsConstant (diff ) : count ;
31
+ }
32
+
33
+ public static void main (String [] args ) {
34
+ Scanner s = new Scanner (System .in );
35
+ System .out .print (KaprekarsConstant (s .nextLine ()));
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments