Java 为什么我会得到无穷大的答案
所以,我已经尝试了多种不同的方法,但是当我在最后一次输出中运行它时,我仍然得到了无穷大的答案,你认为问题是什么?第一个输出工作正常,但第二个和第三个输出工作不正常。指数应该是Java 为什么我会得到无穷大的答案,java,output,infinity,Java,Output,Infinity,所以,我已经尝试了多种不同的方法,但是当我在最后一次输出中运行它时,我仍然得到了无穷大的答案,你认为问题是什么?第一个输出工作正常,但第二个和第三个输出工作不正常。指数应该是^12*5。我不是在做数学.pow对吗 import java.util.Scanner; public class CompoundInterest { public static void main(String[] args) { Scanner input = new Scanner(S
^12*5
。我不是在做数学.pow
对吗
import java.util.Scanner;
public class CompoundInterest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double principal = 0;
double rate = 0;
double time = 0;
double one = 0;
double three = 0;
double five = 0;
double a, b;
System.out.print("Enter the amount of the loan: ");
a = input.nextDouble();
System.out.print("Enter the Rate of interest : ");
b = input.nextDouble();
one = a * Math.pow((1 + b/12),Math.pow(12,1));
three = a * Math.pow((1 + b/12),Math.pow(12,1));
five = a * Math.pow((1 + b/12),Math.pow(12,5));
System.out.println("");
System.out.println("The Compound Interest after 1 year is : "
+ one);
System.out.println("");
System.out.println("The Compound Interest after 3 years is : "
+ three);
System.out.println("");
System.out.println("The Compound Interest after 5 years is : "
+ five);
}
}
你把某个东西提升到了
12^5
的力量,它的大小是荒谬的,应该是无穷大
试一试
相反。你把某个东西提升到了
12^5
的力量,它的大小是荒谬的,应该是无穷大
试一试
相反。您实际上获得了两种权力,例如在第二行(五年期利息):
five=a*Math.pow((1+b/12),Math.pow(12,5))代码>
这可以归结为:a*(1+b/12)^(12^5)
。在普通32位或64位计算机上,这是一个接近无穷大的数字
尝试使用a*Math.pow((1+b/12),12*年)
其中年数
是利息年数。您实际上是在取两个幂,例如在第二行(五年利息的幂):
five=a*Math.pow((1+b/12),Math.pow(12,5))代码>
这可以归结为:a*(1+b/12)^(12^5)
。在普通32位或64位计算机上,这是一个接近无穷大的数字
尝试使用a*Math.pow((1+b/12),12*年)
其中年数
是利息年数。取12*5的幂。为什么不干脆做^60
?到12*5的倍数。为什么不直接执行^60
?这会产生一个数字。是指向表意文字的链接。这会产生一个数字。是连接到表意文字的链接。
five = a * Math.pow((1 + b/12), 12*5);