473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Another java.lang.ArrayIndexOutOfBoundsException

Can anyone tell me why j gets the value of y, instead of 0 in the following snippet?
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2. public class matrix 
  3. {
  4.     public int x,y;
  5.     public void init(int[][] matrix1)
  6.     {
  7.         int i;
  8.         int j;
  9.         Scanner input = new Scanner(System.in);
  10.         System.out.printf("Enter x:");
  11.         x=input.nextInt();
  12.         System.out.printf("Enter y:");
  13.         y=input.nextInt();
  14.         matrix1 = new int[x][y];
  15.  
  16.         for( i=0 ; i<x ; i++)
  17.         {    
  18.             for( j=0 ; j<y ; j++);
  19.             {
  20.                 //System.out.println("enter:");
  21.                 System.out.printf("%d %d",i,j);
  22.                 matrix1[i][j]=0;
  23.  
  24.             }
  25.         }
  26.     }
  27. }
  28.  
Jun 27 '11 #1
3 2348
Nepomuk
3,112 Expert 2GB
At which point to you get the value of y for j? The inner for-loop will increase j until it's equal to y, but that's the idea, right? Or are you having problems understanding how a for-loop works?
Jun 27 '11 #2
I solved it.The problem was at line 18 - i haven't noticed the semi-column after the for-loop.
Jun 28 '11 #3
Nepomuk
3,112 Expert 2GB
Ah, one of those mistakes you easily make but are difficult to find... Well done for doing so yourself! :-)

Greetings,
Nepomuk
Jun 28 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: CM | last post by:
Hi, when i want connect me in my BD with a JSP (with this simple code), this exception is throw. Thank's for ur help Mathieu CODE of my JSP ---------------------
6
by: ganesh.m | last post by:
Hi, I am new to DB2. I am getting this error while loading the DB2Driver. I don't have any idea about where i might have gone wrong. please help me. Below is the stack trace. Stack Trace:...
0
by: snkssa | last post by:
Hi, I got the following error while building an application with ant. please can you give the solution or reason why it is failing? Thank you create_zip_linux: ...
22
oll3i
by: oll3i | last post by:
i get Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at Producent.main(producent.java:605) when i run it from bat @start "Supply Chain Management-Producer to...
3
by: jayattarde | last post by:
Hi, While running .jar file I get the following error. Please helpme to sort it out. ption in thread "main" java.lang.NoClassDefFoundError: while resolving class: Cutter at...
6
by: Light | last post by:
Hi I m getting this error while i m trying to run my program and i don't understand why that happens. import java.util.*; public class Exercise6 {
1
by: shaikhussain | last post by:
public class EmployeeServicesTestCase { /** * @param args */ public static void main(String s)throws Exception { // TODO Auto-generated method stub BeanFactory beans=new...
2
by: David Rothabuer | last post by:
I work with an integration engine that is java based. All my scripting is javascripting and I've run into a problem that I can't find a solution to. I am getting this error when I attempt to read...
1
by: Buena Velasco | last post by:
I'm having trouble finding the error on my code. I know what "Exception thread ... ArrayIndexOutOfBounds... " means but I couldn't tell which part in the looping it is or in other. import...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.