Math.pow--无法找到符号?

问题描述:

我在尝试计算程序中创建的每月抵押贷款金额时遇到了麻烦,一旦试图编译代码,我得到的错误'找不到符号 - 方法inter(双)' 计算月利率的公式是 -Math.pow--无法找到符号?

我目前认为,双重价值无法看到在switch语句之外,但我不太确定问题在这里。 ._;

感谢您的帮助!

我的代码:

import java.util.*; 


public class MorgageCalculator 
{ 
public static void main(String[]args) 
    { 
     Scanner s = new Scanner(System.in); 
     double principal = 0;//principle amount 
     int period =0;//number of years required to pay out mortgage 
     double inter =0; //interest rate 
     int amr =0;//monthly payments 
     char another ='y'; 
     double monthly=0; 
     String input; 
     System.out.println("Enter principle amount, value cannot be negative"); 
     principal=s.nextDouble(); 
     while(principal <=0){ 


      while(inter==0){ 
       System.out.println("Enter mortage term: (1,2,3,5,10)"); 
       period=s.nextInt(); 
      switch(period){ 
       case 1: 
       inter=3.5; 
       break; 
       case 2: 
       inter=3.9; 
       break; 
       case 3: 
       inter=4.4; 
       break; 
       case 5: 
       inter=5.0; 
       break; 
       case 10: 
       inter=6.0; 
       break; 
       default: 
       inter=0; 

      } 
      if(inter==0){System.out.printf("%f is not a valid period, please enter a new one \n",period); 
      } 
     } 
       System.out.printf("The inter rate for the term will be %.2f \n",inter); 
      while(amr==0){ 
       System.out.println("Enter morgage amortization period (5,10,15,20,25)"); 
      amr=s.nextInt(); 
       switch(amr){ 
        case 5: 
        amr= 5*12; 
        break; 
        case 10: 
        amr= 10*12; 
        break; 
        case 15: 
        amr= 15*12; 
        break; 
        case 20: 
        amr= 20*12; 
        break; 
        case 25: 
        amr= 25*12; 
        break; 
        default: 
        amr= 0; 
       } 
       if(amr==0){ 
        System.out.printf("%f is not a valid amortization period, please enter a new one."); 
       } 
      } 
inter=inter/100; 
monthly=(principal(Math.pow(inter(1+inter),amr))/(Math.pow(1+inter,amr)-1)); 

        } 

    } 

    } 
+1

请张贴相关的代码,最好是一个[最小化,完整和可验证的示例程序](http://stackoverflow.com/help/mcve),这里有你的问题,而不是链接。链接可能死了,链接可能包含大型程序,程序也可能大要求一个志愿者审查。您对此要求的遵守将不胜感激,并可能帮助您获得更好,更快的帮助。 – 2014-09-29 23:50:24

+0

您应该在此处发布您的代码 – 2014-09-29 23:50:27

间是一个变量,而不是方法。在这一行你试图使用它作为一个方法:

 monthly = (principal(Math.pow(inter(1 + inter), amr))/(Math.pow(
       1 + inter, amr) - 1)); 

在你的最后一行(其中分配给monthly,你缺少一个乘法运算符替换inter(1 + inter)inter*(1 + inter)

+0

非常感谢你! :)我知道这是愚蠢的。 – Krissyten 2014-09-29 23:56:15

+0

@Krissyten - 很高兴帮助。在将来,如果您发布了编译器在发生类似错误时所抱怨的行,那么在此处获得响应将会有所帮助。或者,更好地,发布整个代码并通过插入的评论或摘录指出相关的行。 – 2014-09-29 23:58:38