-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuntime.java
39 lines (32 loc) · 1.34 KB
/
Runtime.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
import java.lang.String;
import java.util.Locale;
import java.util.Scanner;
public class Runtime {
private static Scanner scan = (new Scanner(System.in)).useLocale(Locale.ROOT);
public static void printInt (int n) {
System.out.println(n);
}
// Use the ROOT locale to force a decimal dot rather than the country-specific decimal separator.
public static void printDouble (double x) {
// The following attempt fixes the precision to 5 digits
// and thus differs from a vanilla println(x).
//
// System.out.println(String.format(Locale.ROOT, "%f", x));
//
// I did not find an way to reproduce exactly the behavior of println(x)
// using String.format. Someone may find one, but I ran out of steam.
// (E.g. I was suprised to learn that the code of Double.toString(),
// invoked by println(double), does not invoke a formatter like String.format
// but is instead a very ugly custom code: getBinaryToASCIIConverter(double).)
//
// Thus, for now I resort to the hacky solution to just globally set the locale.
Locale.setDefault(Locale.ROOT);
System.out.println(x);
}
public static int readInt () {
return scan.nextInt();
}
public static double readDouble () {
return scan.nextDouble();
}
}