Java Reference
In-Depth Information
else if (richter >= )
r = " ";
and copy it. This is usually done by highlighting with the mouse and then
selecting Edit and then Copy from the menu bar. If you follow Productivity Hint
5.2 , you are smart and use the keyboard. Hit Shift+End to highlight the entire
line, then Ctrl+C to copy it. Then paste it (Ctrl+V) multiple times and fill the
text into the copies. Of course, your editor may use different commands, but the
concept is the same.
The ability to copy and paste is a lways useful when you have code from an
example or another project that is similar to your current needs. To copy, paste,
and modify is faster than to type everything from scratch. You are also less
likely to make typing errors.
A DVANCED T OPIC 5.2: The switch Statement
A sequence of if/else/else that compares a single value against several
constant alternatives can be implemented as a switch statement. For example,
int digit;
. . .
switch (digit)
{
case 1: System.out.print("one"); break;
case 2: System.out.print("two"); break;
case 3: System.out.print("three"); break;
case 4: System.out.print("four"); break;
case 5: System.out.print("five"); break;
case 6: System.out.print("six"); break;
case 7: System.out.print("seven"); break;
case 8: System.out.print("eight"); break;
case 9: System.out.print("nine"); break;
default System.out.print("error"); break;
}
This is a shortcut for
int digit;
. . .
if (digit == 1) System.out.print("one");
Search WWH ::




Custom Search