【发布时间】:2013-12-09 03:12:40
【问题描述】:
我一直在努力学习扫描仪课程。我似乎无法理解它的方法。我正在尝试运行一组对我来说似乎正确的代码。我尝试了一些调整,但仍然没有。为什么我收到此错误的任何提示
“线程“主”中的异常 java.util.InputMismatchException 在 java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(未知来源)在 java.util.Scanner.nextInt(未知来源)在 java.util.Scanner.nextInt(未知来源)在 PolynomialTest.main(PolynomialTest.java:18)"
public class PolynomialTest {
public static void main(String[] args) throws IOException {
Scanner fileData = new Scanner(new File("operations.txt"));
Polynomial math = new Polynomial();
int coeff = fileData.nextInt();
int expo = fileData.nextInt();
while (fileData.hasNext()) {
Scanner nextTerm = new Scanner(fileData.nextLine());
if (nextTerm.next().equalsIgnoreCase("insert")) {
math.insert(coeff, expo);
System.out.println("The term (" + coeff + ", " + expo
+ ") has been added to the list in its proper place");
System.out.println("The list is now: " + math.toString());
} else if (nextTerm.next().equalsIgnoreCase("delete")) {
math.delete(coeff, expo);
System.out.println("The following term has been removed ("
+ coeff + ", " + expo + ")");
System.out.println("The list is now: " + math.toString());
} else if (nextTerm.next().equalsIgnoreCase("reverse")) {
math.reverse();
System.out
.println("The list was reversed in order and the list is now: "
+ math.toString());
} else if (nextTerm.next().equalsIgnoreCase("product")) {
System.out.println("The product of the polynomial is: "
+ math.product());
} else {
System.out.println("Not a recognized input method");
}
nextTerm.close();
}
PrintWriter save = new PrintWriter("operations.txt");
save.close();
fileData.close();
}
【问题讨论】: