我正在尝试读取一个包含 6 个元素的文本文件并将其放入两个数组中。我要阅读的文本的第一个元素是字符串,第二个元素是双精度。但是,当我调用println
验证输出时,它会打印null
和0.0
.
import java.io.*;
import java.util.*;
public class inputFile {
public static void main(String[] args) throws FileNotFoundException{
String [] studNum = new String [25];
double [] grade = new double [25];
File findFile = new File ("//Users//luiserojas//Documents//holaFile.txt");
Scanner inFile = new Scanner (findFile);
int index = 0;
while (inFile.hasNext()){
studNum [index] = inFile.next();
grade [index] = inFile.nextDouble();
index ++;
System.out.println(studNum[index] + grade[index]);
}
}
}