Sunday, 8 September 2013

text file returning null and 0.0

text file returning null and 0.0

I am trying to read a text file with 6 elements in it and put it into two
arrays. The first element of the text I'm trying to read is a string and
the second is a double. However when I call println to verify the output,
it prints null and 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]);
}
}
}

No comments:

Post a Comment