0
import java.util.*;

class CompoundInterest

{
    
public static void main()

    {
        Scanner s = new Scanner(System.in);
        
        System.out.println("Enter Principal Amount");
        float p = s.nextFloat();
        
        System.out.println("Enter Time Period i.e. number of years");
        float t = s.nextFloat();
        
        System.out.print("Enter Rate of Interest");
        float r = s.nextFloat();
        
        float a = p * (Math.pow(((1+ (r/100))), t));
        
        float ci = a-p;
        
        System.out.println("Compound Interest = " +ci);
        System.out.println("Amount = " +a);
    }
}

我收到这样的错误:

精度损失

必需:浮动

发现:双

1 个错误

4

1 回答 1

0

老兄!!java.lang.Math.pow(double,double) 接受两个双精度参数并返回一个双精度值..您已将浮点参数作为实际参数传递给该方法..由于强制它们被转换为双精度。但是在返回时您是将返回值分配给无法自动强制的浮点值!!因此,要么将其显式转换为浮点数,要么将其分配给双变量……不惜一切代价,它应该只返回双精度值

于 2013-09-22T05:34:23.583 回答