The question is:
Write a code that will take and inches input and convert it to mm. Then display the same result using m, cm, and mm. Example would be:
Input:
53 inches
Output:
1346 mm
OR
1 m 34 cm and 6 mm
Something is happening with the remainder conversion that is not calculating the cm and mm right. I know I should probably using casting, but I'm not sure how to. Can someone help?
Thank you.
import java.util.Scanner;
import java.text.DecimalFormat;
public class Format
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
System.out.print ("Enter a number in inches: ");
double inches = scan.nextInt();
double firstmm = inches * 25.4;
double m = inches * 0.0254;
inches = inches % 0.0254;
double cm = inches * 100;
inches = inches % 100;
double mm = inches * 10;
inches = inches % 10;
DecimalFormat fmt = new DecimalFormat ("0");
System.out.println (fmt.format(firstmm) + " mm");
System.out.println ("OR");
System.out.print(fmt.format (m) + " m ");
System.out.print(fmt.format (cm) + " cm and ");
System.out.print(fmt.format (mm) + " mm");
}
}