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;
        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}} );

            }
            }
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  why we are using http protocol in servlets
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  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  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 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  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  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  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  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
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 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
C Program....PLEASE HELP
C Program....PLEASE HELP  For this assignment, you are to write a program that calculates points along a rhodonea curve, a.k.a. a mathematical rose..., and pointers. I am lost and need a little help starting please *int fillArray
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 explain this program
please explain this program  public class MainClass { public static void main(String[] args) { System.out.println("Java
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
please solve this program
please solve this program  Build a package EMPPACK that contains one stored function Validatesal() and two stored procedures Insertemp() and Getempdetails().The Insert_emp() procedure inserts a particular employee
please correct this program
please correct this program  import java.util.Scanner; public class Nam { public static void main (String arg[]) { String[] name={"Aki","Karthi","Tk","Suba","Malu","Buvi","Janu","Sara","Sandy","Abi","Ani","Amu
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
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
plese tell me the control flow of this program
plese tell me the control flow of this program  public class starForTest { public static void main(String [] args) { for (int... k....? plese tell me the control flow
Java Program(Please reply asap)
Java Program(Please reply asap)  Find out the ways in which numbers can be added to get the same result Example:- 10 1+9=10 1+2+3+4=10 1+9=10
Please explain me the flow of this program..
Please explain me the flow of this program..  // Substring replacement. class StringReplace { public static void main(String args[]) { String org = "This is a test. This is, too."; String search
please explain me the flow of this program
please explain me the flow of this program  class Bticket extends Thread { Object train,comp; Bticket(Object train,Object comp){ this.train=train; this.comp=comp; } public void run(){ synchronized
please tell me the difference between local variable, staitic variables, and instance variables....
please tell me the difference between local variable, staitic variables, and instance variables....  please tell me the difference between local variable, staitic variables, and instance variables
please give me an idea to develop a program for this question?
please give me an idea to develop a program for this question?  How to enter a text or number from keyboard without using InputStreamReader method in java
please help me in coding this given program
are the prime numbers in ascending order write a program to find the nth term in this series. (i m unable to code this program..please provide solution...please help me in coding this given program  consider the below
please help me in coding this given program
are the prime numbers in ascending order write a program to find the nth term in this series. (i m unable to code this program..please provide solution...please help me in coding this given program  consider the below
please help me for this program - Java Beginners
please help me for this program   Write a program that asks the user for a starting value and an ending value and then writes all the integers (inclusive) between those two values. Enter Start: 10 Enter End: 14 10
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Please write code for this program in java and Explain it ? pl'sssssssss
Please write code for this program in java and Explain it ? pl'sssssssss  Question: We are given an array of 2n integers wherein each pair...;  wow i got also same program. ok leave it. in this program they are passing
please help me in a java program !! - Java Beginners
please help me in a java program !!  the porgram should use...://en.wikipedia.org/wiki/Kosaraju_algorithm) there are 4 classes in my program : Vertex... and run the program" i still need to modify the method kosaraju in the class Graph
Please provide the java code for the given program.
Please provide the java code for the given program.   We need an application for managing an educational institute. That application should provide the details of Students Courses Faculty Fee details etc..,   
Please tell me how I can access a field (data type char) of resultset in a java class
Please tell me how I can access a field (data type char) of resultset in a java class  I have created a table named empdetails in postgreSql 8.4...("empsex")); as erroneous. There is no method like getChar() also. Please tell me

Ads