Statement
Write a class that declares a variable named inches, which holds a length in
inches, and assign a value. Display the value in feet and inches; for example, 86
inches becomes 7 feet and 2 inches. Be sure to use a named constant where
appropriate. Save the class as InchesToFeet.jav.
public class InchesToFeet {
public static void main(String[] args) {
int lenght_in_inches=86;
int lenght_in_feet=86/12;
int lenght2_in_inches=86%12;
System.out.println("your lenght will be: "+lenght_in_feet+ " feet"+" and "+lenght2_in_inches+ " inches");
}
}
Explanation
This statement is asking you to create a class called “InchesToFeet” that contains a variable named “inches”, which will hold a length in inches. You should assign a value to this variable.
You are then asked to display the value of “inches” in feet and inches. For example, if “inches” is 86, the output should be “7 feet and 2 inches”.
You should also use a named constant where appropriate. A named constant is a value that is assigned once and cannot be changed later.
Finally, you should save the class as “InchesToFeet.java”.
Leave a Reply