這是針對初學者的 Java 課程。我不斷收到“掃描儀無法決議為型別”錯誤。我正在使用 Visual Studio 和 JDK 16.0.2 我也剛剛安裝了 Visual Studio 并在這臺筆記本電腦上安裝了 Java。我正在為我的班級撰寫這個 Mortgage Calculator 程式,它在我添加用于捕獲用戶輸入錯誤的 while 回圈之前就起作用了。現在它給了我以前沒有的“掃描儀”錯誤。我添加并移動了幾行代碼,突然間它給了我這個“掃描儀”錯誤。下面是整個代碼:
package com.phillip;
import java.text.NumberFormat;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
final byte MONTHS_IN_YEAR = 12;
final byte PERCENT = 100;
int principal = 0;
float monthlyInterest = 0;
int numberOfPayments = 0;
Scanner scanner = new Scannner(System.in);
while (true) {
System.out.println("Principal: ");
principal = scanner.nextInt();
if (principal >= 1000 && principal <= 1_000_000) {
break;
}
System.out.println("Enter a value between 1000 and 1000000");
}
while (true) {
System.out.println("Annual Interest Rate: ");
float annualInterest = scanner.nextFloat();
if (annualInterest >= 1 && annualInterest <= 30) {
monthlyInterest = annualInterest / PERCENT / MONTHS_IN_YEAR;
break;
}
System.out.println("Enter a value between 1 and 30");
}
while (true) {
System.out.println("Period (Years): ");
byte years = scanner.nextByte();
if (years >= 1 && years <= 30) {
numberOfPayments = years * MONTHS_IN_YEAR;
break;
}
System.out.println("Enter a value between 1 & 30");
}
double mortgage = principal
* (monthlyInterest * Math.pow(1 monthlyInterest, numberOfPayments))
/ (Math.pow(1 monthlyInterest, numberOfPayments) - 1);
String mortgageFormatted = NumberFormat.getCurrencyInstance().format(mortgage);
System.out.println("Mortgage: " mortgageFormatted);
}
}
uj5u.com熱心網友回復:
我相信你有一個錯字
Scanner scanner = new Scannner(System.in);
“掃描儀”而不是“掃描儀”
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/313893.html
上一篇:與本地主機資料庫的連接錯誤c#
