以下程序旨在计算简单的利息给定公式 i = p*r*t,给定用户输入并将其放入自己的方法(必须),但是,在运行它时,我收到错误“未处理的异常类型 IOException。 ..” 我之前尝试实现一个 try catch 块,但它导致了更多错误
import java.io.*;
public class cInterest {
public static void main(String[] args) throws IOException {
}
public static double balance(double principal, double rate, double years) {
double amount = 0;
String input;
BufferedReader myInput = new BufferedReader(new InputStreamReader(
System.in));
System.out.print("How much would you like to take out? ");
input = myInput.readLine();
principal = Double.parseDouble(input);
System.out.print("Enter the interest rate: ");
input = myInput.readLine();
rate = Double.parseDouble(input);
for (int i = 1; i < years; i++) {
amount = principal * rate * years;
amount += principal;
}
return amount; // - principal;
}
}