我不断收到 "Scanner cannot be resolved to a type" 错误。我正在使用 Java 和 Visual Studio,这是给初学者的 Java class
I keep getting an "Scanner cannot be resolved to a type" error. I am using Java and Visual Studio and this is for a beginner Java class
这是给初学者的 java class。我不断收到“扫描仪无法解析为类型”错误。我正在使用 Visual Studio 和 JDK 16.0.2 我也刚刚在这台笔记本电脑上安装了 Visual Studio 和 Java。我正在为我的 class 编写这个抵押贷款计算器程序,它在我添加 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);
}
}
我相信你打错了
Scanner scanner = new Scannner(System.in);
'Scannner' 而不是 'Scanner'
这是给初学者的 java class。我不断收到“扫描仪无法解析为类型”错误。我正在使用 Visual Studio 和 JDK 16.0.2 我也刚刚在这台笔记本电脑上安装了 Visual Studio 和 Java。我正在为我的 class 编写这个抵押贷款计算器程序,它在我添加 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);
}
}
我相信你打错了
Scanner scanner = new Scannner(System.in);
'Scannner' 而不是 'Scanner'