Java Reference
In-Depth Information
the body of the method
main
. (The reasons for declaring variables in the body of the
method
main
are explained in Chapter 7.) The body of the method
main
will also
contain the Java statements that implement the algorithm. Therefore, for this pro-
gram, the definition of the method
main
has the following form:
2
public static void
main(String[] args)
{
declare variables
statements
}
To write the complete conversion program, follow these steps:
1. Begin the program with comments for documentation.
2. Use
import
statements to import the classes required by the program.
3. Declare the named constants, if any.
4. Write the definition of the method
main
.
COMPLETE PROGRAM LISTING
//*******************************************************
// Author: D. S. Malik
//
// Program Convert: This program converts measurements
// in feet and inches into centimeters using the formula
// that 1 inch is equal to 2.54 centimeters.
//*******************************************************
import
java.util.*;
public class
Conversion
{
static
Scanner console =
new
Scanner(System.in);
static final double
CENTIMETERS_PER_INCH = 2.54;
static final int
INCHES_PER_FOOT = 12;
public static void
main(String[] args)
{
//declare variables
int
feet;
int
inches;
int
totalInches;
double
centimeters;
System.out.print("Enter feet: ");
//Step 1
feet = console.nextInt();
//Step 2
Search WWH ::
Custom Search