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错误
答案 0 :(得分:0)
哥们!! java.lang.Math.pow(double,double)接受两个双参数并返回一个double值..你已经将float params作为实际参数传递给该方法..由于强制它们被转换为double。但是在返回时你是将返回值分配给浮动值,在该值中无法自动强制!! 因此,要么将其显式转换为浮动,要么将其分配给双变量....不惜任何代价它应该只返回双值