Wednesday, 14 May 2025

🛠 How to Fill a 2D Array In Java

 You can use nested loops to assign values:

for (int row = 0; row < matrix.length; row++) {

    for (int col = 0; col < matrix[0].length; col++) {

        matrix[row][col] = row + col;

    }

}


//matrix[0].length gives the number of columns in 2D arrays.

//matrix.length gives the number of rows in 2D arrays.

No comments:

Post a Comment

👨‍💻 How I Started Learning Java at 15 (and You Can Too)

  When I first heard of Java, I thought it was just something to do with Minecraft mods or Android apps. I didn’t realize it would become my...