String of Characters

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

The loop continues prompting until the user enters an integer greater or equal to 5. (Actually, 5 is dangerously small for a password.)

String of Characters

Next, the program assembles a string of all the characters that could go into a password:

    String choices = "abcdefghijklmnopqrstuvwxyz" ;
    choices = choices + choices.toUpperCase() ;
    choices = choices + "1234567890" ;

The first of these three statements creates a string literal containing the lower case alphabet. Then the expression choices.toUpperCase() creates a string that is all upper case, based on the string currently refered to by choices. This string is then concatenated onto the original choices string:

choices = choices + choices.toUpperCase();

Recall that + means "string concatenation". Finally, the string "1234567890" is concatenated onto the string to produce the final string, shown below:

"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

QUESTION 15:

Would the statement

choices = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

have worked as well?