Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Fill a 2D Array | Arrays
Introduction to Scala
course content

Kursusindhold

Introduction to Scala

Introduction to Scala

1. Getting Started
2. Variables and Data Types
3. Conditional Statements and Loops
4. Arrays
5. Strings

book
Challenge: Fill a 2D Array

Task

Your task create a 3x2 2D array of integers named matrix and fill it with elements which have the value of equal to i + j, where i is the row index, and j is the column index. Use two for loops with the loop variables named i and j to iterate over its indices.

java

Main

copy
123456789101112
object Main { def main(args: Array[String]): Unit = { var ___ = Array.___[___](___, ___) // Create a 3x2 2D array for (___ ___ matrix.___) { // Iterate over the row indices for (___ ___ matrix(___).___) { // Iterate over the columns indices matrix(___)(___) = ___ // Assign the sum of indices to the current element print(matrix(___)(___) + " ") } println() } } }

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 6

Spørg AI

expand
ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

course content

Kursusindhold

Introduction to Scala

Introduction to Scala

1. Getting Started
2. Variables and Data Types
3. Conditional Statements and Loops
4. Arrays
5. Strings

book
Challenge: Fill a 2D Array

Task

Your task create a 3x2 2D array of integers named matrix and fill it with elements which have the value of equal to i + j, where i is the row index, and j is the column index. Use two for loops with the loop variables named i and j to iterate over its indices.

java

Main

copy
123456789101112
object Main { def main(args: Array[String]): Unit = { var ___ = Array.___[___](___, ___) // Create a 3x2 2D array for (___ ___ matrix.___) { // Iterate over the row indices for (___ ___ matrix(___).___) { // Iterate over the columns indices matrix(___)(___) = ___ // Assign the sum of indices to the current element print(matrix(___)(___) + " ") } println() } } }

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 6
Vi beklager, at noget gik galt. Hvad skete der?
some-alt