令牌上的语法错误";"在Java中

时间:2014-07-19 19:10:42

标签: java

"令牌上的语法错误";",此令牌后预期的原始类型"是这句话"String data = input.next(); "上的半结肠后我得到的信息,我不知道为什么。

import java.util.*;
public class PorterHouse {
    public static void main(String[] args){
System.out.println("enter interest rate, loan mount, and number of years: ex. "+
    " 7.9-400000-5");
Scanner input = new Scanner(System.in);

String data = input.next(); 

[] b = data.split("[-]");
double interstRate = Double.parseDouble(b[0]);
double loanPrincipal = Double.parseDouble(b[1]);
double loanLength = Double.parseDouble(b[2]);
double monthlyPayment = (b[1]*b[2] / 1);
double totalPayment = ( monthlyPayment * loanLength * 12);
System.out.println("Monthly Pament: " + monthlyPayment);
System.out.println("totalPayment: " + totalPayment);


}
}

2 个答案:

答案 0 :(得分:2)

尝试改变这一点:

[] b = data.split("[-]");

用这个:

string[] b = data.split("[-]");

目前[] b没有数据类型。所以要为它提供数据类型。

答案 1 :(得分:1)

我想而不是:

[] b = data.split("[-]");

你需要这样的东西:

String[] b = data.split("[-]");

您可能想要替换:

double monthlyPayment = (b[1]*b[2] / 1);

by:

double monthlyPayment = (loanPrincipal * loanLength  / 1); //idk why divide by 1??

cuz,b[1]b[2]是两个字符串。