Challenge: Uppercase Even Words
Task
Swipe to start coding
Your task is to convert each word at an even position to uppercase and return the modified string.
- Split the input string into an array of words using the
split(" ")
method from the String class. - Create an object for building the result string step by step using the
StringBuilder
class. - Loop through all elements of the
array
. - Inside the loop, check if the index is even using the remainder operator
%
with 2. - If the index is even, convert the corresponding word to uppercase using the
toUpperCase()
method. - If the index is odd, append the word as is.
- After the loop, convert the result to a string using the
toString()
method.
Solution
solution.java
Everything was clear?
Thanks for your feedback!