【问题标题】:Compound Interest using scanner使用扫描仪的复利
【发布时间】:2013-09-22 05:25:10
【问题描述】:
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 个错误

【问题讨论】:

    标签: java time rate principal


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-06
      • 2013-06-05
      • 2017-04-27
      • 1970-01-01
      相关资源
      最近更新 更多