Forum Stats

  • 3,875,092 Users
  • 2,266,805 Discussions
  • 7,912,078 Comments

Discussions

ArrayIndexOutOfBoundException...!(having problem in inserting values in 2D array for matrix)

2694075
2694075 Member Posts: 1
edited Jun 15, 2014 5:10PM in New To Java

public class matrix_mul

{

  static int a[][],b[][],k;

  public static void main(String o[])

  {

       k=0;

       a=new int[3][3];

       b=new int[3][3];

       for(int i=0;i<3;i++)

       {

            for(int j=0;j<3;i++)

            {

                 a[i][j]=Integer.parseInt(o[k++]);

            }

           

       }

       for(int i=0;i<3;i++)

       {

            for(int j=0;j<3;i++)

            {

                 b[i][j]=Integer.parseInt(o[k++]);

            }

           

       }

       for(int i=0;i<3;i++)

       {

       for(int j=0;j<3;i++)

            {

            System.out.println(a[i][j]);

            }

           

       }

       for(int i=0;i<3;i++)

       {

            for(int j=0;j<3;i++)

            {

                 System.out.println(b[i][j]);

            }

           

       }

     }

}


well, this is my code for inserting values in 2D array for matrix & then printing it on Command line

   but it's show AraayIndexOutOfBoundExcepton 3 or sometimes 1 (on cmd)
  i m new to this language so plz help

Tagged:

Answers

  • well, this is my code for inserting values in 2D array for matrix & then printing it on Command line 
       but it's show AraayIndexOutOfBoundExcepton 3 or sometimes 1 (on cmd)
    

    That's probably because you just tried to cut & paste code and then never fixed the errors

    for(int j=0;j<3;i++)

    The loop variable is 'j'; why are you incrementing 'i'?

    You do that in at least TWO places.

This discussion has been closed.