Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in
Sequence
Reversing the words of a sentence
Core exercise
Write inverserMots(String phrase) that returns the sentence with its words in reverse order. Words are separated by a single space: "je suis etudiant" becomes "etudiant suis je".
A workshop goes here: you write and run code in it. It requires JavaScript.
Starting code
Exercices.java
public class Exercices {
public static void main(String[] args) {
System.out.println(inverserMots("je suis un etudiant"));
}
public static String inverserMots(String phrase) {
// TODO : indice - phrase.split(" ")
return "";
}
}
The core exercise is validated in the workshop, which requires JavaScript.
Hint 1
phrase.split(" ") returns a String[]. Walk through it backwards, gluing the pieces back together, and watch out for the extra space at the end.