import java.io.File; //import file library
import java.io.FileNotFoundException; //import exception library
import java.util.Scanner; //import the scanner libary
class Main {
public static void main(String[] args) {
//create and empty array to hold info from the file
String [] namesFromFile = new String [10];
int [][] gradesFromFile = new int [10][4];
//create a counter for the array position
int arrayPositionCounter = 0;
try //try everything inside the brackets..
{
//make a new scanner and point to file location
Scanner textFileScanner = new Scanner(new File("Names.txt"));
//loop through entire file
while (textFileScanner.hasNextLine())
{
namesFromFile[arrayPositionCounter]=textFileScanner.nextLine();
System.out.println(namesFromFile[arrayPositionCounter]);
arrayPositionCounter +=1;
gradesFromFile[arrayPositionCounter]=textFileScanner.nextLine();
System.out.println(gradesFromFile[arrayPositionCounter]);
arrayPositionCounter +=1;
}
//close the file scanner when we're done
textFileScanner.close();
}
catch (FileNotFoundException e) //catch the error
{
System.out.println("OH NO!!!! NO FILE EXISTS!!!");
e.printStackTrace(); //display the specific error
}
}
}
Nick
89
78
90
60
Zak
67
72
47
83
Justyn
23
53
78
54
Amber
68
70
78
85
Tyler
70
78
84
92
Connor
88
94
78
95
Xander
66
78
96
80
Taylor
61
55
46
70
John
76
77
80
83
Lee
80
84
92
78