import java.util.Scanner; public class masyvai { public void masyvas() { //sk – 5 , z – 2,4,6,8 Scanner scan2 = new Scanner(System.in); int a,b; System.out.printf("Iveskite eiluciu kieki"); a=scan2.nextInt(); System.out.printf("Iveskite stulpeliu kieki"); b=scan2.nextInt(); int mtr[][] = new int[a][b]; System.out.println(" --------------------------------------------------"); System.out.println("| Sumavimas | Atimtis |"); System.out.println(" --------------------------------------------------"); for (int eil = 0; eil < a; eil++) { for (int stul = 0; eil < b; stul++) { System.out.print(" "+mtr[eil][stul]); // error here, wtf??? } System.out.print("\n"); } scan2.close(); } }
What can be the problem here? I really dont understand, I used this code on my netbook (XP win) and it works fine but when i used it on my pc (win7) it crashes and gives me a gift:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at masyvai.masyvas(masyvai.java:28)