Java Reference
In-Depth Information
System.out.println();
System.out.print("Enter inches: ");
//Step 3
inches = console.nextInt();
//Step 4
System.out.println();
System.out.println("The numbers you entered are "
+ feet + " for feet and "
+ inches + " for inches.");
//Step 5
totalInches = INCHES_PER_FOOT * feet + inches;
//Step 6
System.out.println();
System.out.println("The total number of inches = "
+ totalInches);
//Step 7
centimeters = totalInches * CENTIMETERS_PER_INCH;
//Step 8
System.out.println("The number of centimeters = "
+ centimeters);
//Step 9
}
}
Sample Run: (In this sample run, the user input is shaded.)
Enter feet: 15
Enter inches: 7
The numbers you entered are 15 for feet and 7 for inches.
The total number of inches = 187
The number of centimeters = 474.98
The programming code of this program must be saved in the file Conversion.
java because we named the class containing the method main Conversion .
The preceding program uses comments such as //Step 1 , //Step 2 , and so on.
The only purpose of these comments is to show which step of the algorithm (shown
before the program listing) corresponds to which statement in the program. We
typically use this convention in all the programming examples in this topic.
 
Search WWH ::




Custom Search