Java Reference
In-Depth Information
. . .
public void withdraw(double amount)
{
if (amount <= balance)
{
double newBalance =
balance -
amount;
balance = newBalance;
}
}
. . .
}
It crowds the code too much to the right side of the screen. As a consequence, long
expressions frequently must be broken into separate lines. More common values
are two, three, or four spaces per indentation level.
How do you move the cursor from the leftmost column to the appropriate
indentation level? A perfectly reasonable strategy is to hit the space bar a sufficient
number of times. However, many programmers use the Tab key instead. A tab
moves the cursor to the next tab stop. By default, there are tab stops every eight
columns, but most editors let you change that value; you should find out how to set
your editor's tab stops to, say, every three columns.
186
187
Some editors help you out with an autoindent feature. They automatically insert as
many tabs or spaces as the preceding line because the new line is quite likely to
belong to the same logical indentation level. If it isn't, you must add or remove a
tab, but that is still faster than tabbing all the way from the left margin.
As nice as tabs are for data entry, they have one disadvantage: They can mess up
printouts. If you send a file with tabs to a printer, the printer may either ignore the
tabs altogether or set tab stops every eight columns. It is therefore best to save and
print your files with spaces instead of tabs. Most editors have settings that convert
tabs to spaces before you save or print a file.
A DVANCED T OPIC 5.1: The Selection Operator
Java has a selection operator of the form
Search WWH ::




Custom Search