Results 1 to 4 of 4
  1. #1
    soc86 is offline Member
    Join Date
    Oct 2008
    Posts
    39
    Rep Power
    0

    Default i want my answer to a whole number or i think an int, please help?

    I want my answer to a whole number, any advise??


    public class inc2cm{

    public static void main (String[]arg) {

    double inches;
    double centimetres;



    System.out.println("How many inches?");
    inches=UserInput.readDouble();

    centimetres = inches*2.75+0.5;



    System.out.println("inches into centimetres is"centimetres);


    }
    }

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Make casting,
    Java Code:
    double inches;
    int centimetres;
    centimetres =(int)( inches*2.75+0.5);

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Something is wrong...

    Although the program would appear to work, the values being used are wrong (as Norm has already pointed out):

    • 1 inch = 2.54 cms


    Also, why is 0.5 being added on to the convertion ?

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

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

    Default

    why is ...
    One shouldn't have to ask that question of an ... programmer. He would comment his code to describe what it is that the code is doing.
    Since instructors don't require students to comment their code, that is what you get.

Similar Threads

  1. Plz answer this question ...
    By raghu2114 in forum Advanced Java
    Replies: 2
    Last Post: 09-19-2008, 06:36 PM
  2. kindly answer the queston in attachment file
    By abhinav_jain09 in forum Advanced Java
    Replies: 11
    Last Post: 09-19-2008, 04:47 PM
  3. guss which is correct answer
    By abhinav_jain09 in forum Java Applets
    Replies: 4
    Last Post: 09-19-2008, 02:39 AM
  4. What is the answer to this strange problem:
    By willemjav in forum New To Java
    Replies: 5
    Last Post: 08-11-2008, 09:31 PM
  5. What is the answer yo my problem with this code
    By masaka in forum New To Java
    Replies: 4
    Last Post: 03-26-2008, 06:33 AM

Posting Permissions

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