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){

	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();
			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){
				for(int valueq1 : q1){
				//	//outFile.println(valueq1);

What is the program supposed to do? There is a lot of code with no comments explaining why your are doing things. Add comments to describe what each section of code does.

Where is the printing of valueq1?
Why do you think the output from your program is wrong?
What do you want the program to do?

Without the data, its hard to understand what you are talking about.

A suggestion for code while you're debugging it. Put the data in the program and print the output to the console. For example:

String InputData = "1234 4 5 6 7 8 234 10 11 12 13 14 345 15 16 17 18 19"; 
      Scanner inFile= new Scanner(InputData);
      PrintWriter outFile= new PrintWriter(System.out);
This article has been dead for over six months. Start a new discussion instead.