- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为我的 java 类做实验,我做了这个,但无论我如何尝试修复它,我总是收到错误。我知道问题出在我的 switch
语句中的 case 1
下。我尝试重新排序 infiles 并将 inFile.nextLine();
添加到列表的开头、结尾和中间,但这也不起作用
这是错误:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at Lab6.main(Lab6.java:73)
这是我的代码:
import java.util.Scanner;
import java.io.*;
public class Lab6
{
public static int menu()
{
int ans;
System.out.println("Please chose an option");
System.out.println("1.Class Average");
System.out.println("2.Student Average");
System.out.println("3.Standard Deviation");
System.out.println("4.Letter grades");
System.out.println("5.Minimum/Maximum");
System.out.println("6.Locate : ");
System.out.println("7.Locate All students where the difference between exam1 and exam2>15%");
System.out.println("8.Histogram");
System.out.println("9.Update data");
System.out.println("10.Quit");
Scanner keyboard = new Scanner (System.in);
ans=keyboard.nextInt();
return ans;
}
public static void main (String[] args)throws IOException
{
//variables
int choice;
int testno;
int test1,
test2;
int NewScore;
int count;
int sum1,
sum2;
int avg1,
avg2;
String name;
//get choice
Scanner keyboard = new Scanner (System.in);
choice=menu();
File myFile = new File("lab6_indata.txt");
Scanner inFile = new Scanner(myFile);
switch(choice)
{
case 1:
System.out.println("You Chose Class Average\n");
count=1;
sum1=0;
sum2=0;
avg1=0;
avg2=0;
while(count<=25)
{
test1=inFile.nextInt();
test2=inFile.nextInt();
sum1=sum1 + test1;
sum2=sum2 + test2;
count ++;
}
avg1 = sum1 / count;
avg2 = sum2 / count;
System.out.println("Class Average Test 1:"+ avg1);
System.out.println("Class Average Test 2:"+ avg2);
break;
case 2:
System.out.println("You Chose Student Average");
break;
case 3:
System.out.println("You Chose Standard Deviation");
break;
case 4:
System.out.println("You Chose Letter grades");
break;
case 5:
System.out.println("You Chose Minimum/Maximum");
break;
case 6:
System.out.println("You Chose Locate : ");
break;
case 7:
System.out.println("You Chose Locate All students where the difference between exam1 and exam2>15%");
break;
case 8:
System.out.println("You Chose Histogram");
break;
case 9:
System.out.println("You Chose Update data");
System.out.println("Please Enter Name");
name=keyboard.nextLine();
System.out.println("Are you updating test number 1 or 2?");
testno=keyboard.nextInt();
System.out.println("What is the new score?");
NewScore=keyboard.nextInt();
break;
case 10:
System.out.println("Program Ended");
break;
default:
System.out.println("Error: Invaild option");
break;
}
inFile.close();
}
}
这是我的文件:
*Robert 70 82
*Joel 64 50
*Alice 98 95
*Jasmine 76 92
*Larry 42 69
*Elizabeth 79 85
*Frank 75 66
*Christine 20 36
*Alex 0 52
*Ariel 84 81
*Luis 65 77
*Nicole 40 89
*Mitch 90 94
*Randy 88 86
*Tammy 91 84
*Sarah 78 71
*Samuel 80 66
*Lauren 55 63
*Deanna 97 99
*Mathew 100 87
*Justin 68 76
*Beth 96 95
*Rebecca 85 83
*Paul 44 65
*Lucy 34 56
也许我的 inFile 需要采用不同的格式?
最佳答案
每行中的第一个标记是一个String
,因此需要在读取任何整数之前使用它
String studentName = inFile.next();
test1 = ...
关于java - 线程 "main"java.util.InputMismatchException 中出现异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16094613/
我在这个网站上发布的代码有这个问题 https://developers.google.com/drive/quickstart-cs是 Google Drive 快速入门的开发人员站点。我按照网站上
我正在尝试制作一个非常简单的 Kafka Producer,目前正在关注 producer example除了我的制作人没有分区程序类。 将所需文件导出到 jar 后,我将它们传输到我的 Linux
问题 在java中,我有一个“Util项目”,在进行单元测试时使用另一个“Mock项目”。 我的问题是“模拟项目”也使用“Util项目”来构建一些模拟对象。 当我使用 Maven 构建项目时,我无法构
据我所知,这些包已经存在很长时间了。但是,我从未见过它们的实际用法。而且这些包似乎不成熟,不再维护。如果是,为什么这些包现在存在? 最佳答案 包裹automata被 scala.xml.dtd 使用,
关闭。这个问题需要debugging details .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Improve this question Co
在java.util.Collections中,有一个方法: public static void fill(List list, T obj) 用第二个参数指定的对象填充第一个参数指定的List。
我不明白它要我做什么。分配给 sentence正在工作: val sentences : java.util.List[CoreMap] = document.get(classOf[Sentence
在我的 React 应用程序中,我想使用一些实用程序。我见过两种不同的方法。第一个是,只是创建函数并将其导出。第二个是,创建一个 Util 类并导出一个对象,这样它就不能被实例化(静态类)。 clas
我有一个 util 类,它接受 String jwtToken 和 Key key 并使用 io.jsonwebtoken.jwts 解码 jwt。 但是,我无法对此进行测试。原因是,我无法模拟公钥并
我有使用目标命名空间的专有架构 xmlns:ax216="http://util.java/xsd" 这给我带来了从 java (java.util.xsd) 开始生成禁止的(由 Java 安全管理器
我正在阅读集合以查看 Javadocs 中的实现层次结构。 Collections声明为public class Collections extendds Object Collection声明为pu
我正在使用 Spring-boot 应用程序,我可以在其中连接 Azure 应用程序配置。但是当我尝试使用内容类型应用程序/JSON 读取值时出现错误。 我的Java类 @ConfigurationP
我正在使用 Spring-boot 应用程序,我可以在其中连接 Azure 应用程序配置。但是当我尝试使用内容类型应用程序/JSON 读取值时出现错误。 我的Java类 @ConfigurationP
我在使用格式说明符时遇到问题。这是否意味着我正在使用 %d? public static void main(String[] args) { double y, x; for (x =
鉴于此代码 import java.util.Iterator; private static List someList = new ArrayList(); public static void
我正在 HackerEarth 解决问题,我无法弄清楚为什么我的程序在命令行上正确运行并给出正确的结果,但在代码编辑器上运行时却给出 java.util.NoSuchElementException
我正在尝试使用以下代码使用对象列表列表中的数据填充tableModel readExcel.readSheet(0): TableModel tableModel = new DefaultTabl
java.util.Set 、 java.util.List 和其他 Collection 接口(interface)不可序列化。需要一个简单、直接的解决方案来在可序列化的 POJO 中使用它。 pu
我试图从 servlet 返回数据库搜索结果的 ArrayList 以显示在 jsp 页面上。 在servlet中设置arraylist作为请求的属性,并将请求转发到jsp页面。当我尝试在 jsp 页
我是android新手,最近我试图从firebase中提取数据到recyclerview/cardview中以垂直布局显示数据,它显示将Hashmap转换为Arraylist的错误,其中代码是:
我是一名优秀的程序员,十分优秀!