-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotation.java
More file actions
37 lines (35 loc) · 1020 Bytes
/
Rotation.java
File metadata and controls
37 lines (35 loc) · 1020 Bytes
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
import java.lang.Math;
class Rotation {
/*Variable doc -
X - The number of digits in the number
n - The given integer
K - The given number of rotation(s)*/
static int countDigit(int n) {
int X = 0;
while(n>0) {
n = n/10;
X++;
}// end of while loop
return X;
}// end of countDigit
public static void kRotation(int n, int K) {
int X = countDigit(n);
K = K % X;
if (K<0) {
K = X + K;
}// end of if block
int extNo = n / (int) Math.pow(10, K);
n = n % (int) Math.pow(10, K);
int size = countDigit(extNo);
for (int i=1; i<=size; i++){
n *= 10;
}// end of for loop
n = n + extNo;
System.out.println(n);
}//end of kRotation
public static void main(String[] args) {
int N = 12345;
int K = -2;
kRotation(N, K);
}// end of main
}//end of Rotation