-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathDigitsAfterPoint.java
41 lines (35 loc) · 1.24 KB
/
DigitsAfterPoint.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
package digits_after_point;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;
import java.util.StringTokenizer;
public class DigitsAfterPoint {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileReader("input.txt"));
StringTokenizer st = new StringTokenizer(sc.nextLine(), " ");
int a = Integer.valueOf(st.nextToken());
int b = Integer.valueOf(st.nextToken());
int k = Integer.valueOf(st.nextToken());
String symbol;
if(a % b == 0){
symbol = "0";
}else {
BigDecimal c = new BigDecimal(String.valueOf(a));
BigDecimal d = new BigDecimal(String.valueOf(b));
BigDecimal div;
if(k > 6 && (b != 7)){
div = c.divide(d, 6, RoundingMode.DOWN);
}else {
div = c.divide(d, k%6, RoundingMode.DOWN);
}
String number = String.valueOf(div);
symbol = number.substring(number.length()-1);
}
FileWriter out = new FileWriter("output.txt");
out.write(symbol);
out.close();
}
}