# Conversion of Length

• 09-16-2011, 02:19 AM
irnie1994
Conversion of Length
Code:

import java.util.*;
public class convert{
static Scanner console = new Scanner(System.in);

public static void main(String[] args) {

int centimeter;

System.out.print("Enter the length in centimeters:  ");
centimeter = console.nextInt();
System.out.println();

System.out.println("inch = " + ((int) ( (centimeter / 2.54 ) + 0.5)));
System.out.println("yard = " + ((int) ( (centimeter / 2.54 ) + 0.5)) / 36 );
System.out.println("feet = " +  ((int) ( (centimeter / 2.54 ) + 0.5)) % 36 / 12 );
System.out.println("inch = " + ((int) ( (centimeter / 2.54 ) + 0.5)) % 12 );
}
}

kindly explain for me??
cuz i didn't know what use of 2.54, 0.5 and % 12 and %36... if u can explain all can u help meh to understand this..?
• 09-16-2011, 02:54 AM
Norm
Re: Conversion of Length
2.54 and 0.5 are numbers that are used in the equation to compute a value.

% is the remainder operator. It returns the remainder after a division. For example: 4 % 3 = 1

12 and 36 are the divisors for the remainder computations. 40 % 36 = 4 and 15 % 12 = 3

What is printed out when you execute the program?