I have been trying to read a file, put it in an array and then find the average of the integers in the array. However I am unsuccessful with putting an integer in each slot of an array.
When I print qa1[0] I get a long chain of 30 but when i print valueq1 I get 303060306090306090120
( My code might look a bit weird right now since i have been trying various things beforehand. )
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class test2 {
int sid;
int q1;
int q2;
int q3;
int q4;
int q5;
public test2(int sid,int q1,int q2,int q3,int q4,int q5){
this.sid=sid;
this.q1=q1;
this.q2=q2;
this.q3=q3;
this.q4=q4;
this.q5=q5;
}
public static void main(String[] args) throws FileNotFoundException
{
Scanner inFile= new Scanner(new FileReader("c:/GradeBook.txt"));
PrintWriter outFile= new PrintWriter("c:/GradeBook.out");
outFile.println("Stud Q1 Q2 Q3 Q4 Q5");
inFile.findInLine("Stud Qu1 Qu2 Qu3 Qu4 Qu5 ");
List<Integer> sid= new ArrayList<Integer>();
List<Integer> q1= new ArrayList<Integer>();
List<Integer> q2= new ArrayList<Integer>();
List<Integer> q3= new ArrayList<Integer>();
List<Integer> q4= new ArrayList<Integer>();
List<Integer> q5= new ArrayList<Integer>();
while (inFile.hasNextInt())
{
int s= q1.size();
sid.add(inFile.nextInt());
q1.add(inFile.nextInt());
q2.add(inFile.nextInt());
q3.add(inFile.nextInt());
q4.add(inFile.nextInt());
q5.add(inFile.nextInt());
int[] sid1= new int[sid.size()];
int[] qa1= new int[q1.size()];
int[] qa2= new int[q2.size()];
int[] qa3= new int[q3.size()];
int[] qa4= new int[q4.size()];
int[] qa5= new int[q5.size()];
//int i=0;
//for(int valueq1 : q1){
//qa1[i]=valueq1;
//i++;
//}
for(int valueq1 : q1){
// //outFile.println(valueq1);
outFile.println(qa1[0]);
}
}
inFile.close();
outFile.close();
}
}