samedi 28 mars 2015

Java: Array List Printing object reference instead of array



I'm am very much a rookie when it comes to coding. What I'm trying to accomplish is to load grades from a txt file and put them into an existing array.


I have actually solved this. and In the program the array does retain the values. But when I got to print them I get the object reference aka [I@5c647e05 rather than the array. Below is my code.



public static void main(String[] args) {
int[] list = new int[15];
Scanner in = null; // create a scanner object
loadGrades(in, list);

System.out.println(list);
}

public static void loadGrades(Scanner in, int[] list) {

int grades; // int variable
try { // try
in = new Scanner(new FileReader("Proj5Data.txt"));// change filename
} catch (FileNotFoundException ex) { // catch
System.out.println("File not found");
System.exit(1);
}
for (int i = 0; i < list.length; i++) {
grades = in.nextInt(); // var
list[i] = grades ;// put the int in the array at the counter value
}
in.close();

}


Print results as:



[I@5c647e05
BUILD SUCCESSFUL (total time: 0 seconds)



Aucun commentaire:

Enregistrer un commentaire