怎样求出22/7小数点后的100位数?急需...
------解决方案--------------------
- Java code
public static void main(String[] args) { BigDecimal a = new BigDecimal(22); a = a.divide(new BigDecimal(7), 100,BigDecimal.ROUND_HALF_UP); System.out.println(a); }
------解决方案--------------------
- Java code
public class Test { public static void main(String[] args) { System.out.println(div7(22, 100)); // 22/7 的第 100 位 System.out.println(div7(33, 100)); // 33/7 的第 100 位 } public static int div7(int numerator, int digit) { int mod = numerator % 7; if(mod == 0) { return 0; } String repetend = "142857"; int[] shift = {0, 2, 1, 4, 5, 3}; char c = repetend.charAt((digit + shift[mod - 1] - 1) % 6); return c - '0'; }}