You want to know how many feet is 3.5 yards, and how many inches is 3.5 yards. Write a program that will provide a conversion. Remember that 1 yard is 3 feet and 1 feet is 12 inches.
public class DistanceConverter { public static void main(String args[]) { double yards = 3.5; final int FEET_TO_YARDS = 3; final int INCHES_TO_FEET = 12;
System.out.println("the number of feet in " + yards + " is " + (yards * FEET_TO_YARDS)); System.out.println("the number of inches in " + yards + " is " + yards * FEET_TO_YARDS * INCHES_TO_FEET); } } The problem with the program above is that using "magic numbers" will make it hard to maintain and debug. Write an application and use constants to solve this problem. Make the output nice and readable. |
Nenhum comentário:
Postar um comentário