我正在读取两行 .txt 文件(ui.UIAuxiliaryMethods; 用于此)来计算患者的 BodyMassIndex(BMI),但是当达到 patientLenght 时,我得到一个 inputmismatchexception。这是我的两行输入,由 \t 分隔:
Daan Jansen M 1.78 83
Sophie Mulder V 1.69 60
它按名称 - 性别 - 长度 - 重量排序。这是我将所有元素保存在字符串、双精度和整数中的代码:
package practicum5;
import java.util.Scanner;
import java.io.PrintStream;
import ui.UIAuxiliaryMethods;
public class BodyMassIndex {
PrintStream out;
BodyMassIndex() {
out = new PrintStream(System.out);
UIAuxiliaryMethods.askUserForInput();
}
void start() {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
String lineDevider = in.nextLine(); //Saves each line in a string
Scanner lineScanner = new Scanner(lineDevider);
lineScanner.useDelimiter("\t");
while(lineScanner.hasNext()) {
String patientNames = lineScanner.next();
String patientSex = lineScanner.next();
double patientLength = lineScanner.nextDouble();
int patientWeight = lineScanner.nextInt();
}
}
in.close();
}
public static void main(String[] args) {
new BodyMassIndex().start();
}
}
有人对此有解决方案吗?