Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Question [Problem] Enhanced for-loop with 2D arrays (or array in array)

    SOLVED : I m stupid I had to write this line for(int i=0;i<=forbiddenloc.length-1;i++) {
    Because the array starts from 0 and length starts counting from 1 I guess.
    Java Code:
    	public void keyPressed(KeyEvent e) {
    			boolean allowedposition=true;
    			int keyCode = e.getKeyCode();
    			if(keyCode == KeyEvent.VK_ESCAPE) {
    				stop();
    			}else if(keyCode == KeyEvent.VK_DOWN && y<=704){
    			for(int i=0;i<=forbiddenloc.length;i++) {
    					i[U]f(x==Integ[/U]er.parseInt(forbiddenloc[i][0]) && y+32==Integer.parseInt(forbiddenloc[i][1])) {
    						allowedposition=false;
    					}
    				}
    				if(allowedposition==true) {
    					y+=32;
    				}
                          }
                          ...
                 }
    Anyway , if someone else has a better way to go trough 2D-array with a loop , please share ...
    Last edited by thewrongsyntax; 10-07-2012 at 09:02 PM.

Similar Threads

  1. Enhanced For Loop Array List Reference Question
    By smande3 in forum New To Java
    Replies: 1
    Last Post: 06-30-2012, 03:42 AM
  2. Replies: 5
    Last Post: 03-29-2012, 06:22 PM
  3. Using enhanced for loop to print array list??
    By bdl1127 in forum New To Java
    Replies: 1
    Last Post: 02-19-2012, 12:43 AM
  4. Array and Loop Problem
    By javadog in forum New To Java
    Replies: 2
    Last Post: 09-04-2011, 12:38 PM
  5. Adding Arrays and Enhanced For Loop into program.
    By vinyacam in forum New To Java
    Replies: 1
    Last Post: 05-10-2010, 06:28 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •