Results 1 to 2 of 2
  1. #1
    scottmulla is offline Member
    Join Date
    Mar 2011
    Rep Power

    Exclamation Program that truncates a number

    Hi am i new to java and i am trying to write this basic program with methods however it will not work and i am not sure why. and suggestions would be great thanks.

    A screenshot of the program/errors are here.

    Pictures by scottmulla - Photobucket

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    London, UK
    Blog Entries
    Rep Power


    it is very difficult to follow code from a picture, especially a low resolution picture, so it would be appreciated if you would copy + paste the code here wrapped in [code] /code tags next time. anyhow, from the screenshot i did notice the error message you got:

    "java.lang.String cannot be applied to java.lang.Double"

    when you get any message like that it means you made a type-mismatch, which happens when the java compiler is expecting a variable to be of a certain type i.e. Double but it is fed with another type i.e. String.

    as an example, you cannot do the following:
    Java Code:
    String today = "25";
    Double tomorrow = today + 1;

    without first converting the String in question to a Double like this:
    Java Code:
    Double tomorrow = Double.parseDouble(today) + 1;

    the same works the other way around too, you cannot do the following:
    Java Code:

    because the function "println" only takes the type String, so you must first convert the double "tomorrow" back to a string like this:
    Java Code:

    hope this helps..
    Last edited by ozzyman; 03-25-2011 at 09:49 PM.

Similar Threads

  1. smallest number java program
    By elmo in forum New To Java
    Replies: 9
    Last Post: 11-18-2010, 09:29 PM
  2. Replies: 5
    Last Post: 11-17-2010, 05:53 PM
  3. Phone number Program ..
    By Sary in forum New To Java
    Replies: 9
    Last Post: 03-17-2010, 07:15 PM
  4. A Number Converting Program!
    By WastedxYears in forum New To Java
    Replies: 2
    Last Post: 01-09-2010, 12:47 AM
  5. Replies: 8
    Last Post: 04-22-2008, 03:21 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