Results 1 to 2 of 2
  1. #1
    irnie1994 is offline Member
    Join Date
    Aug 2011
    Posts
    28
    Rep Power
    0

    Default Conversion of Length

    Java 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..?
    Last edited by sunde887; 09-16-2011 at 03:37 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default 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?

Similar Threads

  1. Difference between length() and length
    By mitra in forum New To Java
    Replies: 7
    Last Post: 07-28-2011, 12:46 AM
  2. help with length
    By ama91 in forum New To Java
    Replies: 15
    Last Post: 02-21-2011, 01:44 AM
  3. String.length?
    By rizowski in forum New To Java
    Replies: 7
    Last Post: 11-20-2010, 05:33 PM
  4. string length HELP PLZ!!
    By vette427 in forum Eclipse
    Replies: 1
    Last Post: 09-23-2010, 06:12 AM
  5. Integer length
    By jithan in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 03:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •