-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateANumber.java
More file actions
37 lines (32 loc) · 763 Bytes
/
RotateANumber.java
File metadata and controls
37 lines (32 loc) · 763 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
package Data_Structure_And_Algorithm;
import java.util.Scanner;
public class RotateANumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int temp = n;
int nod = 0;
while (temp>0){
temp/=10;
nod++;
}
if(k<0){
k+=nod;
}
k = k % nod;
int div = 1;
int mul = 1;
for (int i = 1; i <=nod ; i++) {
if(i<=k){
div*=10;
}else {
mul*=10;
}
}
int q = n/div;
int r = n%div;
int rot = mul*r +q;
System.out.println(rot);
}
}