使用分母2到14(包括分子小于分母)打印所有适当分数的十进制等值表。将小数点数舍入为5位。
import java.text.*;
public class Decimal
{
public static void main(String[] arg)
{
int d;
int n=1;
float Sum;
DecimalFormat Form = new DecimalFormat("0.00000");
for(d=2;d<=14;d++)
{
do
{
Sum= n/d;
System.out.println(n+"/"+d+" "+Form.format(Sum));// Problem here I assume,why is the sum always Zero????!!
n++;
}while(n!=d);
n=1;
}
}
}
答案 0 :(得分:0)
您将int除以int;结果是一个整数。必须将其中一个int转换为double数据类型才能获得正确的结果。
DECLARE @index INT
,@ran_no INT
,@counter INT
,@i INT
SET @i = 1
WHILE @i <= 18
BEGIN
SELECT @index = count(basket_seq)
FROM dbo.test
WHERE basket_seq = @i
AND flag = 'left'
BEGIN
UPDATE dbo.test
SET @ran_no = convert(INT, 1 + @index * RAND(CHECKSUM(NEWID())))
,@ran_no = (
CASE
WHEN convert(INT, 1 + @index * RAND(CHECKSUM(NEWID()))) NOT IN (
SELECT seq_no
FROM dbo.test
WHERE basket_seq = @i
AND flag = 'left'
)
THEN @ran_no
END
)
,seq_no = @ran_no
WHERE basket_seq = @i
AND flag = 'left'
END
SET @i = @i + 1
END