Using Java, given a number which is the measurement of a distance in millimeter, change the representation of this number to the format of: x meters y centimeters and z millimeters. For example, if the number is 12345 millimeters, display the message: “12345 millimeters = 12 meters 34 centimeters and 5 millimeters”.
import java.util.Scanner; public class MillimetersToMetersCM { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int millimeters, meters, centimeters, n; System.out.print("Enter number of millimeters: "); millimeters = scan.nextInt(); n = millimeters; meters = millimeters/1000; millimeters = millimeters % 1000; centimeters = millimeters / 10; millimeters = millimeters % 10; System.out.println(n+" millimeters = "+meters+" meters "+centimeters+" centimeters and "+millimeters+" millimeters"); } }
Get Answers For Free
Most questions answered within 1 hours.