2D Array Grade Example
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
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]+" ");
}
}
}
}
Java
INFO