题目描述
输入正整数a,b,c 其中$1≤a,b<106,c≤100$输出$a/b$的小数形式,精确到小数点后的c位,例如$a=1,b=6,c=4$输出应该是$0.1667$
输入
多组输入,每行有3个正整数$a,b,c$
输出
输出$a/b$的小数形式,精确到小数点后的c位,
样例输入
样例输出
1 2
| 0.1667 0.50000000000000000000
|
题解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import java.util.Scanner; import java.io.BufferedInputStream; import java.math.RoundingMode; import java.io.BufferedOutputStream; import java.io.PrintWriter; import java.math.BigDecimal; public class Main { static Scanner cin = new Scanner(new BufferedInputStream(System.in)); static PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out)); public static void main(String[] args) { while (cin.hasNext()) { BigDecimal a = cin.nextBigDecimal(); BigDecimal b = cin.nextBigDecimal(); int k = cin.nextInt(); cout.println(a.divide(b, k, RoundingMode.HALF_UP)); } cin.close(); cout.close(); } }
|