0
BankInterest (93 행) 오류가 발생했습니다. 파싱하는 동안 파일 끝에 도달했는데 누구나 내가 왜 이것을 얻고 있는지 알 수 있습니까? 아래에 내 코드가 있으므로 문제의 원인을 파악할 수 있습니다.ERROR 구문 분석 중에 파일 끝에 도달 했습니까?
미리 감사드립니다.
import java.nio.file.*;
import java.util.*;
import java.io;
public class BankInterest {
public static void main(String[] args) throws IOException {
/* TASK 1: Declare variables */
String accountType;
double principal;
double rate;
double balance;
int year;
/* Check if the expected command line is provided */
if (args.length < 1) {
/* Display the Usage */
System.out.println("Usage: java BankInterest interestRateFileName");
/* Programs quits with an error code */
System.exit(-1);
}
/* TASK 2: Read interest rates from a file */
try {
Scanner x = new Scanner(Paths.get("commbank.txt"));
System.out.println(x.nextDouble());
} catch (IOException e) {
/* TASK 3: Take user input - Which Account */
Scanner keyboard = new Scanner(System.in);
System.out.println("Which Account: ");
System.out.println("1 - Savings");
System.out.println("2 - Term Deposits");
String line = keyboard.nextLine();
if (line.equals("1")) {
accountType = "Savings";
} else if (line.equals("2")) {
accountType = "Term Deposits";
}
/* TASK 4: Take user input - Principal and Period */
Scanner input = new Scanner(System.in);
System.out.println("Principal: ");
principal = keyboard.nextDouble();
System.out.println("Years: ");
year = keyboard.nextInt();
/* TASK 5: Calculate balance for the chosen account type */
if (accountType == "Savings") {
balance = principal * Math.pow((1 + rate/100), year);
} else if (accountType == "Term Deposits") {
balance = (principal * rate * time)/100;
}
/* TASK 6: Display results */
if (accountType == "Savings") {
System.out.println("");
System.out.println("The Compound Interest is: " + balance);enter code here
} else if (accountType == "Term Deposits") {
System.out.println("");
System.out.println("The Simple Interest is: " + balance);
} else {
System.out.println("");
System.out.println("Error! Account is not recognized.");
}
}
닫힌 중괄호'}'가 없습니다. – Satya
java의 문자열 비교에'equals()'를 사용하십시오. Ex'if (accountType == "Savings")'는 (accountType.equals ("Savings"))'이어야합니다. – Satya
task3가 앞으로 catch 블록에서 실행되는 이유는 무엇입니까? 왜 새로운 Systen.in 스캐너를 열 수 있습니까? –