Challenge: Applying String Methods in Practice
Task
Your task is the following:
-
Create a mutable
String
variable namedsentence
with the following value: " Today we are going to lea.rn S.cala ". -
Remove leading and trailing whitespaces using the appropriate method and save the result in the
sentence
variable. -
Create an array of words (strings) named
words
based on thesentence
string using the appropriate method. Words are separated by whitespaces. -
Iterate over the indices of the
words
array using the appropriate property. -
Remove the dots from each word by replacing the dot
.
with an empty string using the appropriate method. -
Print the current word (each word should be printed on a separate line).
Main.java
1234567891011object 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 } } }
Tak for dine kommentarer!
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Spørg mig spørgsmål om dette emne
Opsummér dette kapitel
Vis virkelige eksempler
Awesome!
Completion rate improved to 2.86
Challenge: Applying String Methods in Practice
Stryg for at vise menuen
Task
Your task is the following:
-
Create a mutable
String
variable namedsentence
with the following value: " Today we are going to lea.rn S.cala ". -
Remove leading and trailing whitespaces using the appropriate method and save the result in the
sentence
variable. -
Create an array of words (strings) named
words
based on thesentence
string using the appropriate method. Words are separated by whitespaces. -
Iterate over the indices of the
words
array using the appropriate property. -
Remove the dots from each word by replacing the dot
.
with an empty string using the appropriate method. -
Print the current word (each word should be printed on a separate line).
Main.java
1234567891011object 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 } } }
Tak for dine kommentarer!