/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { } public static List<Integer> getDigits(double d) { List<Integer> result = new ArrayList<>(); while (d > 0) { int mostSignificantDigit = (int) d; result.add(mostSignificantDigit); d = (d - mostSignificantDigit) * 10; } return result; } }
Standard input is empty
3.125 can be perfectly represented in base 2 : [3, 1, 2, 5] But 3.1415 can't : [3, 1, 4, 1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 8, 1, 1, 8, 8, 3, 9, 7, 6, 1, 8, 8, 2, 5, 5, 4, 7, 3, 9, 7, 1, 3, 6, 6, 8, 8, 2, 3, 2, 4, 2, 1, 8, 7, 5]