Java Reference
In-Depth Information
Indentation Practices
You may have noticed in the previous examples that certain statements were indented. Java
is a free-form language, meaning that it does not matter where you place statements relat-
ive to each other on a line. However, over the years, a common and accepted indentation
style has developed that allows for very readable programs. This topic follows that style,
and it is recommended that you do so as well. Using this style, you indent one level after
each opening brace, and move back out one level after each closing brace. Certain state-
ments encourage some additional indenting; these will be covered later.
Try This 1-2 Improving the Gallons-to-Liters Converter
You can use the for loop, the if statement, and code blocks to create an improved version of
the gallons-to-liters converter that you developed in the first project. This new version will
print a table of conversions, beginning with 1 gallon and ending at 100 gallons. After every
10 gallons, a blank line will be output. This is accomplished through the use of a variable
called counter that counts the number of lines that have been output. Pay special attention
to its use.
1. Create a new file called GalToLitTable.java .
2. Enter the following program into the file:
 
Search WWH ::




Custom Search