Student Grades

Run Settings
LanguageJava
Language Version
Run Command
import java.io.File;//import file liabary import java.io.FileNotFoundException; //import execption libary import java.util.Scanner;// import the scanner libary class Main { public static void main(String[] args) { String [] StudentsFromFile = new String [10]; int arrayPositionCounter = 0; try{ //make a scanner Scanner textFileScanner = new Scanner(new File("SudentGrades.txt")); //loop through the file and read everyline while (textFileScanner.hasNextLine()) { StudentsFromFile [arrayPositionCounter]=textFileScanner.nextLine(); System.out.println(StudentsFromFile[arrayPositionCounter]);// print out the line arrayPositionCounter +=1; } // close the file scanner when we're done textFileScanner.close();//stop Scanning at the end of the file } catch(FileNotFoundException e) //catch the error { System.out.println("oh no.... no file exists"); e.printStackTrace();//display the specific error } } }
Michael 78 Christopher 90 Jessica 50 Matthew 60 Ashley 70 Jennifer 68 Joshua 58 Amanda 80 Daniel 88 David 79 James 89 Robert 59 John 66
Editor Settings
Theme
Key bindings
Full width
Lines