Results 1 to 3 of 3

Thread: Arrayindex [resolved]

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Arrayindex [resolved]

    Does anyone know why this would happen?
    When the first loop is excuted i get an ArrayIndexOutOfBounds
    exception. But the second loopruns fine.
    Code:
    public class Test{
            public static void main(String[] args){
               
             String s = new String("ABC"); 
             char[] c = new char[s.length()];         
             int[] intArray = new int[25]; 
           
             for(int i = 0; i < s.length(); i++){
                  c[s.charAt(i)]++; // array index out of bounds
             }
          
            for(int k = 0 ;k < s.length(); ++k){
              c[s.charAt(k)]++; // runs fine 
            }
      }
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width