Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Applying String Methods in Practice | Strings
Introduction to Scala
course content

Kurssisisältö

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: Applying String Methods in Practice

Task

Your task is the following:

  1. Create a mutableString variable named sentence with the following value: " Today we are going to lea.rn S.cala ".

  2. Remove leading and trailing whitespaces using the appropriate method and save the result in the sentence variable.

  3. Create an array of words (strings) named words based on the sentence string using the appropriate method. Words are separated by whitespaces.

  4. Iterate over the indices of the words array using the appropriate property.

  5. Remove the dots from each word by replacing the dot . with an empty string using the appropriate method.

  6. Print the current word (each word should be printed on a separate line).

java

Main

copy
1234567891011
object Main { def main(args: Array[String]): Unit = { ___ // Create a string ___ // Remove leading and trailing whitespaces val ___ = ___ // Create an array of words for (i <- ___.___) { // Iterate over the indices ___ // Remove the dot ___ // Print the current word } } }

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 5. Luku 4

Kysy tekoälyä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

course content

Kurssisisältö

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: Applying String Methods in Practice

Task

Your task is the following:

  1. Create a mutableString variable named sentence with the following value: " Today we are going to lea.rn S.cala ".

  2. Remove leading and trailing whitespaces using the appropriate method and save the result in the sentence variable.

  3. Create an array of words (strings) named words based on the sentence string using the appropriate method. Words are separated by whitespaces.

  4. Iterate over the indices of the words array using the appropriate property.

  5. Remove the dots from each word by replacing the dot . with an empty string using the appropriate method.

  6. Print the current word (each word should be printed on a separate line).

java

Main

copy
1234567891011
object Main { def main(args: Array[String]): Unit = { ___ // Create a string ___ // Remove leading and trailing whitespaces val ___ = ___ // Create an array of words for (i <- ___.___) { // Iterate over the indices ___ // Remove the dot ___ // Print the current word } } }

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 5. Luku 4
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt