• 0

[java] Small Annoying Problem


Question

import corejava.*;
import java.io.*;

class ClassStatistics
{
	public static void main (String args[])
	{
  int [][] stats;
  stats = new int[40][6];
  
  GetInputFromFile x = new GetInputFromFile (0,0);
  x.getInput (stats);
  

	}
}

class GetInputFromFile
{
	int r, c;

	GetInputFromFile (int x, int y)
	{
  this.r = x;
  this.c = y;
	}

	void getInput (int [][]ary)
	{  
  //int r = 0;
  //int c = 0;

  FileInputStream input = new FileInputStream ("input.txt");
  
  BufferedInputStream bis = new BufferedInputStream (input);
  
  StreamTokenizer st = new StreamTokenizer (bis);
  
  int found = StreamTokenizer.TT_NUMBER; 
 	 
  while ( found != StreamTokenizer.TT_EOF ) 
  { 
 	 ary[r][c] = found;
 	 
 	 found = st.nextToken ();
    
 	 if ( found == StreamTokenizer.TT_NUMBER ) 
 	 { 
    for (r = 1; r < 40; r++)
    {
   	 for (c = 1; c < 40; c++)
   	 {
      ary[r][c] = (int) st.nval; 
      System.out.println (ary[r][c]); 
   	 }
    }
 	 }//end if
  } // end while 
  bis.close ();
	}//end getInput	
}//end class

ok, i dont get it why the hell is it giving me errors. :angry:

i mean, ugggggghhh. ok, i will calm down :)

but yea, can someone point out the error please :cry:

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Just a guess, since I don't know what errors are occurring, but you are defining an array of 6 columns, and in getInput, you're looping through 39 cols.

...
stats = new int[40][6];
...

    for (c = 1; c < 40; c++)
    {
     ary[r][c] = (int) st.nval; 
     System.out.println (ary[r][c]); 
...

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.