122 Part (Web hosting support) II: Writing Your Own Java Programs

122 Part II: Writing Your Own Java Programs Figure 5-10 shows several runs of the program in Listing 5-7. Because the switch has no breakstatements in it, fall-through happens all over the place. For instance, when the user selects verse 2, the computer executes the two statements in case 2: out.print ( He s a pain, ); out.println( he s a pain, ); Then, the computer marches right on to execute the two statements in case 1: out.print ( Has no brain, ); out.println( has no brain, ); That s good, because the song s second verse has all these lines in it. Figure 5-10: Running the code of Listing 5-7. Notice what happens when the user asks for verse 6. The switchstatement in Listing 5-7 has no case 6 and no default, so none of the actions inside the switchstatement are executed. Even so, with statements that print In the rain, in the rainand Ohhhhhhhhright after the switchstatement, the computer displays something when the user asks for verse 6.
Our window web hosting plans are bursting with features and FREE tools, at the very small rate. Sign up today window web hosting.

Leave a Reply