Practice Challenges for Fun
Explore practical Java challenges to improve your understanding of repetition and loops. Learn to change loop directions, count words, detect palindromes, and calculate factorials with while loops through hands-on coding problems.
Quiz
Attempt the following quiz questions:
1.
What are the four steps of a typical while loop? Which steps are repeated?
Show Answer
1 / 7
Challenge 1: Change the direction of a counted loop
1.
Revise the following while loop so that count decrements, but sum has the same value at the end of the loop as it does in the original loop.
Show Answer
Did you find this helpful?
Challenge 2: Count words in a sentence
1.
Using the String method charAt, write a loop that counts the number of words in the string sentence. You can make the following assumptions:
- Words are separated by exactly one blank character
- The string begins and ends with a non-blank character
Show Answer
Did you find this helpful?