+ 1

Exception in thread "main"

I don't know why program will be e [ab] [ac] where an error. I am a beginner, strives for the answer This is the code: public class test { public static void main(String[] args) { System.out.print("this is a test java ,it can realize some intersting function ,and so on. "+"\n"); int A=0; int B=0; int[] maths; maths=new int [4]; int[][]e=new int [4][4]; int ab=-1; int ac=-1; for(int a=0;a<=4;a++) { ab++; for(int c=0;c<=4;c++){ B++; ac++; e[ab][ac]=B; System.out.println(e[ab][ac]); //there,it is wrong. } } if(A<10){ for(int a=0;a<=5;a++){ A++; System.out.println("the nember is "+A); } } } }

6th Aug 2016, 7:56 AM
Angel_zou
4 odpowiedzi
+ 2
Fix two places 1. Array size is 4, so for loop should start from 0 to 3. The code is from 0 to 4. 2. After inner loop(loop c), variable "ac" value need to be reset to -1. So add line ac = -1;
6th Aug 2016, 9:28 AM
WPimpong
WPimpong - avatar
+ 2
oh, thank you, I've been solved:-)
6th Aug 2016, 10:58 AM
Angel_zou
0
first, make sure your variables are all the same case every time you use them. Next on your last line of code tou have +A, try changing that to ++A.
6th Aug 2016, 9:30 AM
Aquarius
Aquarius - avatar
0
wow i didnt know that first one, u thought you had to keep it between 0 and you choice of number. :) cool good to know
6th Aug 2016, 9:33 AM
Aquarius
Aquarius - avatar