2D Array Grade Example

Run Settings
LanguageJava
Language Version
Run Command
import java.io.*; //import everything from java.io import java.util.*; //import everything from java.util class Main { public static void main(String[] args) { String [] students = new String [10]; int [][] grades = new int [10][10]; try{ File f= new File("data.txt"); Scanner s = new Scanner(f); while(s.hasNextLine()) { //nested for loop to sift the information for(int n=0;n<4;n++) { students[n]=s.nextLine(); for(int g=0;g<4;g++) { grades [n][g]= Integer.parseInt(s.nextLine()); } } } s.close(); } catch (FileNotFoundException f){ System.out.println("No File Found!"); } catch (NoSuchElementException n){ System.out.println("No Elements Found!"); } listGrades(students,grades); } public static void listGrades(String[]nameList, int[][]gradeList){ int studentChoice = 2; System.out.print(nameList[studentChoice]+": "); for(int i=1; i<studentChoice; i++){ for(int gradesInRow=0; gradesInRow<4;gradesInRow++){ System.out.print(gradeList[studentChoice][gradesInRow]+" "); } } } }
Student Zero 98 64 48 84 Student One 98 76 48 97 Student Two 91 73 78 93 Student Three 99 77 48 88
Editor Settings
Theme
Key bindings
Full width
Lines