954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help on project

VirusTalker
Newbie Poster
6 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

first of all, you forgot to use code tags, which makes this very difficult to read
I sujest you check the line where the exception occurs, check whether or not you've forgotten a test on it and if you still can't find it, put your code back here in a readable way

code tags, clear distinctions between the different .java files, ...

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

Hi VirusTalker,

Your code seems Ok. However, in the printContents(BufferedReader in) method, after tokenizing the read string from file, try checking if it hasMoreTokens.

Look at the below modified code of your method and try if it works. Hope it does;

private static void printContents(BufferedReader in)
{
double[][] a = new double[MAX_UNKNOWNS][MAX_UNKNOWNS+1];
int i,j;

int numUnknowns = 0;

try{
String line = in.readLine();

while(line != null && line.length() > 0)
{

// read number of unknowns
numUnknowns = Integer.parseInt(line);

// print out unkowns
System.out.println("\nNumber of unknowns: " + numUnknowns);

// read in equations
for(i=0;i 0)System.out.print(" + ");
System.out.print(a[i][j] + "x_" + (j+1));
}

a[i][j] = Double.parseDouble((tok.nextToken()));
System.out.println(" = " + a[i][j]);
}
}

gaussian(a, numUnknowns);

line = in.readLine();
} // end while

} // end try

catch (IOException e)
{
System.out.println("I/O Error");
System.exit(0);
}

catch(NumberFormatException ex)
{
System.out.println("Impropper number encountered in file");
System.exit(0);

}


}

stema08
Newbie Poster
4 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

Its working fine, with no exceptions.

kalyan_au_cse
Newbie Poster
5 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You