Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners please tell the reason for java.lang.ArrayIndexOutOfBoundsException: in program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Abhishek Sharma
please tell the reason for java.lang.ArrayIndexOutOfBoundsException: in program
1 Answer(s)      2 years and a month ago
Posted in : Java Beginners


public class Test {

      public static void show(int x[][],int y[][]){


        int rows = x.length;
        int columns = y.length;
        for (int row = 0; row < rows; row++) {
        for (int column = 0; column <columns; column++) {
            System.out.print(x[row * columns + column]+" ");
        }
        System.out.print("  ");
         for (int column = 0; column < columns; column++) {
            System.out.print(y[row * columns + column]+" ");
        }
         System.out.println();

        }
    }
      public static void main(String a[]) {
            show(new int[][] { {1,2,3}, {4,5,6},{7,8,9}},new int[][] { {11,12,13}, {14,15,16},{17,18,19}} );

            }
            }

Advertisement
View Answers

September 18, 2012 at 11:27 AM


The loops in your code should be used only for iterating the one dimensional array but you are passing two dimensional array. Therefore error occurs. Here is a code that satisfies your requirement.

public class test {

      public static void show(int x[][],int y[][]){
        for(int i=0 ; i < x.length ; i++){    
           for(int j=0 ; j < x[i].length ; j++){
            System.out.print(x[i][j]+" ");
         }
         System.out.print("  ");
           for(int j=0 ; j < y[i].length ; j++){
            System.out.print(y[i][j]+" ");
        }
        System.out.println();
        }
      }
      public static void main(String a[]) {
            show(new int[][] { {1,2,3}, {4,5,6},{7,8,9}},new int[][] { {11,12,13}, {14,15,16},{17,18,19}} );

            }
            }


Related Tutorials/Questions & Answers:
please tell the reason for java.lang.ArrayIndexOutOfBoundsException: in program
please tell the reason for java.lang.ArrayIndexOutOfBoundsException: in program  public class Test { public static void show(int x[][],int y[][]){ int rows = x.length; int columns = y.length
please tell me the flow of execution of this program
please tell me the flow of execution of this program  class Test{ int x; Test(int x){ this.x=x; } static void access(){ System.out.println("x= "+x); }} class Static{ public static void main(String ar[]){ Test obj=new Test(55
Advertisements
please tell me
please tell me  i have created one table,when i close and again login, table name will be there, but its content not displayed, showing as no rows selected, please tell me the reason
please tell me
, but its compiled and run successfully, please tell me the reason...please tell me  class Person{ int age; String name; void Person1(String g,int a){ name=g; age=a; } Person(String s,int i){ name=s; age=i; } void
please tell me
please tell me  Actually i am working on a Project tiitle is JavaMail System, 1)How to configure java mail API and a Demo Program for Sending mail and Receiving using JSP and Servlet
please tell me
please tell me  why we are using http protocol in servlets
please tell me
please tell me  which cmd we use to clear the screen in sql prompt
please tell me
please tell me  why we use public static main(String ar){} in java instead of main
please tell me
please tell me  select * from emp order by 5 desc; in the above what is the meaning of 5, and what its functionality
please tell me
please tell me  what are the topics in core and advaced java....   Hi Friend, Please visit the following links: http://www.roseindia.net/ http://www.roseindia.net/java/ Thanks   Hi Friend, Please visit
please tell me
please tell me  import java.lang.Thread; class Current{ public static void main(String ar[]){ Thread t = Thread.CurrentThread(); System.out.println...(); ^ 1 error tell me the resolution please....   import
please tell me
please tell me  class Person{ string name; int age; void talk(){ System.out.println("my name is"+name); System.out.println...: '}' expected ^ 2 errors, i got this error....... please tell me the resolution
please tell me
please tell me  class Sample{ private double num1,num2; void sample(double x,double y){ num1=x; num2=y; } void Sum(){ double result=num1+num2...(10.6,20.0); ^ 1 error, please tell me the resolution for this...   
please tell me
please tell me  import java.io.*; class SString{ public static void main(String ar[]) throws IOException{ BufferedReader br = new Bufferedreader...)); ^ 1 error please tell me the resolution of this   Hi
please tell me
please tell me  class Person{ int age; String name; void talk(){ System.out.println("my name is:"+name); System.out.println("my age is:"+age); } } class Hash{ public static void main(String ar[]){ Person raju=new Person
please tell me
please tell me   <tr> <td><html:hidden property="tid" value="${user.id}"/></td> <td><bean:write name="user" property="emp_name"/>
please tell me
please tell me  class Reserve extends Thread{ int available=1; int wanted; Reserve(int i){ wanted = i; } public static void...; ^ please tell me the resolution   class Reserve
please tell me
please tell me  class Producer extends Thread { StringBuffer sb; boolean dataprodover = false; Producer(){ sb = new StringBuffer(); } public void... got error as Inner class connot have static declarations pls tell me
please tell me
please tell me  Blockquote Blockquote> BlockquoteBlockquote how to get images from ms access databases to jsp pagesBlockquote   Jsp get image from ms access database Create a table named user(id,name,address,image
please tell me
please tell me  what is the source code if user give wrong user name password the explorer will show incorrect username password   <...); } %> For more information, please go through the following link: http
Software graduates please tell me,
Software graduates please tell me,  How to view image on Frame in swing(or)awt in Java
Software graduates please tell me,
Software graduates please tell me,  How to view image on Frame in swing(or)awt in Java
In tag files,does attribute values accept expressions or not? If not please explain the reason
In tag files,does attribute values accept expressions or not? If not please explain the reason  **Actually when i do manually in tomcat server....... could any body explain this please............** HTTP Status 500 - type
Please tell me the code to generate the below structure
Please tell me the code to generate the below structure  1 2 3 4 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 7 8 9 1 2 8 9 1 9 1 2 8 9 1 2 3 7 8 9 1 2 3 4 6 7 8 9 1 2 3
please tell me about command line arguments in java?
please tell me about command line arguments in java?  please tell me... arguments are the arguments which are sent to the program being called. You can take any number of command-line arguments which may be necessary for the program
Please tell me how can i convert string to timer
Please tell me how can i convert string to timer  Please tell me how can i convert string to timer
please tell me about command line arguments in java?
please tell me about command line arguments in java?  please tell me... arguments are the arguments which are sent to the program being called. You can take any number of command-line arguments which may be necessary for the program
please tell me what is ment by wrapper class in java........
please tell me what is ment by wrapper class in java........  what is ment by wrapper class in java
i have problem with this query... please tell me the resolution if this .........
i have problem with this query... please tell me the resolution if this .........  select length(ename)||' charecters exist in '||initcap(ename)||'s name' as "names and length" from emp
i have problem with this query... please tell me the resolution if this .........
i have problem with this query... please tell me the resolution if this .........  select initcap(ename),job from emp where substr(job,4,length(job,4,3)))='age
Please tell me where I can find tutorials on spring hibernate?
Please tell me where I can find tutorials on spring hibernate?  Hello, Please tell me where I can find tutorials on spring hibernate? Thanks..   Dear Friend, You can find some good tutorials on Spring Hibernate here
 

 

 

DMCA.com