Answer:
A.
public class Main{
public static void main(String[] args) {
final int divisor = 12;
int inches = 86 ,feet;
feet =inches/divisor;
inches = inches%divisor;
System.out.print(feet+" feets "+inches+" inches");
}
}
B.
import java.util.*;
public class InchesToFeetInteractive{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
final int divisor = 12;
int inches,feet;
System.out.print("Measurement in Inches: ");
inches = input.nextInt();
feet =inches/divisor;
inches = inches%divisor;
System.out.print(feet+" feets "+inches+" inches");
}
}
Step-by-step explanation:
Both classes use the same algorithm; however, the slight difference is that
(A) assumes a values of inch measure while (B) prompts user for input
That is show in the differences below
A)
int inches = 86 ,feet; ---> This initializes inches to 86;
B)
This prompts user for measurement in Inches
System.out.print("Measurement in Inches: ");
This gets the measurement
inches = input.nextInt();
The next lines are common in both classes
This declares and initializes a constant which is used in the conversion
final int divisor = 12;
This calculates the number of feet in the user input
feet =inches/divisor;
This gets the remainder inches, if any. It uses % to calculate the remainder
inches = inches%divisor;
This prints the required output
System.out.print(feet+" feets "+inches+" inches");