Reputation: 29
Hey stackoverflow community been working at this program for a few days and been stuck on this error for awhile and can't get past it. Wondering if anyone can offer insight on what is going on. Thanks for all replies.
Here is the output when I run the program:
27050
45200
22600
36250
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at program10.Tax.printBrackets(Program10.java:69)
at program10.Program10.main(Program10.java:16)
Below is some snippets of the source code. Under the main class is:
Tax tx = new Tax();
tx.setFilingStatus(tx.MARRIED_JOINTLY);
tx.setBrackets(2001);
tx.getBrackets();
tx.printBrackets();
Under the tax class I have the printBracket line that it is getting the error at:
public void printBrackets(){
for (int i = 0; i < brackets.length; i++) {
for (int j = 0; i < brackets[0].length; j++) {
System.out.println(brackets[i][j] + " ");
}
}
}
Lastly is the 2001.brackets file it is pulling the information from:
20
27050 45200 22600 36250
65550 109250 54625 93650
136750 166500 83250 151650
297350 297350 148675 297350
2147483647 2147483647 2147483647 2147483647
Upvotes: 0
Views: 54
Reputation: 70
Probably you should say
j < brackets[0].Length
instead of i
in the inner for
loop...
Upvotes: 1
Reputation: 3323
This line
for (int j = 0; i < brackets[0].length; j++)
should be
for (int j = 0; j < brackets[0].length; j++)
Upvotes: 0
Reputation: 29
Nevermind, my printBrackets method was wrong can't believe I overlooked that for so long. Thanks anyways!
Upvotes: 0