Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Java Basics!
You have completed Java Basics!
Preview
In this video, we wrap up the course by introducing a mechanism to continually prompt until a valid response is obtained.
Extra credit
- There is a method on String called contains(). It checks to see if one string is contained within the other. This seems like a good way to build a master list of words that are not allowed. Why don't you see if what they typed is in a long string of bad words.
- After you get that working, attempt to take case into account. If your list of bad words that you maintain is all lower cased, you can check the lower case version of the input in the bad string. How do you make a string lowercase?
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
when a user entered a word
that we wanted to block.
0:00
It would be a much better user experience
if we keep asking
0:00
the user to enter a proper word
until they enter an acceptable one.
0:03
This is a common pattern in programming,
usually solved by using a while loop.
0:08
A while loop runs the same block of code
repeatedly while a condition is true.
0:12
Java also has a nice feature
called a do-while loop.
0:17
This lets us run the code once first,
then check the condition afterward.
0:20
Let's use the do-while loop
to keep prompting the user
0:25
until they enter a valid noun.
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up