0

import java.util.Scanner;

public class MehrdimensionaleArrays {

public static void main(String[] args) {
    
    System.out.println("Wie groß soll ihr Vektor sein?");
    
    int Line;
    int Column;
    
    Scanner sc = new Scanner(System.in);        
    
    Line  = sc.nextInt();
    Column = sc.nextInt();
    
    int[][] Vektor = new int[Line][Column];
    
    for(int i = 0; i < Vektor.length; i++) {
        for(int j = 0; i < Vektor[i].length; j++) {
            
            Vektor[i][j] = (int) (Math.random()*100);
            System.out.print(Vektor[i][j] + ", " );
        }
        
        System.out.println();
        
    }

}

} I am getting an error that says Index X out of bounds for length X and i'm not sure what that means.

  • 1
    Does this answer your question? [What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?](https://stackoverflow.com/questions/5554734/what-causes-a-java-lang-arrayindexoutofboundsexception-and-how-do-i-prevent-it) – OH GOD SPIDERS Jan 05 '22 at 15:01
  • fyi, you have `i < Vektor[i].length;` as a condition in your second loop, which should probably be `j < Vektor[i].length;`. (You are using the wrong counter variable in other words) – OH GOD SPIDERS Jan 05 '22 at 15:10

0 Answers0