Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java array beginner confusion

Basically I would like to store information about a train within arrays. I believe I would need to use a 2d array. I can't seem to get it working correctly. I want an array that will let me keep track of the number of empty and reserved seats on each car of a train. Is this going to work for me?

    int[][] seats = new int[4][10]; 
    for (int row = 0; row < 4; row ++)
        for (int col = 0; col < 10; col++)
            car[row][col] = 0;

I want for this just to initialize all the seats to 0, signifying they are empty. I currently get an error message on the semi colon after int[4][10], it says "expected , {"

like image 425
user2884621 Avatar asked May 25 '26 11:05

user2884621


1 Answers

Your code is valid, the only error is that car should be seats:

int[][] seats = new int[4][10]; 
for (int row = 0; row < 4; row++)
   for (int col = 0; col < 10; col++)
      seats[row][col] = 0;

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!