Results 1 to 14 of 14
  1. #1
    Cruor is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Question Illegal Arithmetic Operations?

    Hello,

    I am currently teaching myself Java, and there is a question asking me in my book which of the following expressions are illegal:

    2.3 * 1.2
    5.67 - 2
    25.0 / 5.0
    7.0 % 3.0
    8 % 2.0

    But after re-reading everything, writing a program containing the expressions, and searching the internet, I have seen nothing wrong with these expressions.

    Could someone point out something I am missing?

    Thanks for your time.

  2. #2
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    fire up your editor, enter them, and see what the compiler says.

  3. #3
    Cruor is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default

    I already have, I guess this means they are all right?

  4. #4
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    None of them is illegal
    I die a little on the inside...
    Every time I get shot.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Cruor View Post
    Hello,

    I am currently teaching myself Java, and there is a question asking me in my book which of the following expressions are illegal:

    2.3 * 1.2
    5.67 - 2
    25.0 / 5.0
    7.0 % 3.0
    8 % 2.0

    But after re-reading everything, writing a program containing the expressions, and searching the internet, I have seen nothing wrong with these expressions.

    Could someone point out something I am missing?

    Thanks for your time.
    All are correct. Who told you that it's illegal? You said that on the editor everything are fine. So...

  6. #6
    Cruor is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default

    The book said "State wether illegal or legal"

    So I guess it might have been a trick question.

    Thanks for the responses, I will be here to stay on the forums :D

  7. #7
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    a more useful question is: do you get the expected answer.
    Put some calls to System.out.println() in your code and see. I bet some will surprise you.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by fishtoprecords View Post
    I bet some will surprise you.
    Yes it is. But they are not illegal anyway. ;)

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Cruor View Post
    The book said "State wether illegal or legal"

    So I guess it might have been a trick question.

    Thanks for the responses, I will be here to stay on the forums :D
    Simply user println() and see the output. Then decide it's legal or illegal.

  10. #10
    tOpach is offline Member
    Join Date
    Sep 2008
    Location
    Ankara-TURKEY
    Posts
    42
    Rep Power
    0

    Default

    I think all of them are corret and my opinion is that dont spend too much time on those definitions.Good luck:D
    A stitch in time saves nine:D

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  12. #12
    tOpach is offline Member
    Join Date
    Sep 2008
    Location
    Ankara-TURKEY
    Posts
    42
    Rep Power
    0

    Default

    "That is not a good opinion I think. Discovering new things make difference always. "

    Yeah, you are right, discovering new things make difference always. And the only thing that we can not bring back is TIME.So, make things faster.


    tOpach,

    Kind regards.
    A stitch in time saves nine:D

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  14. #14
    tOpach is offline Member
    Join Date
    Sep 2008
    Location
    Ankara-TURKEY
    Posts
    42
    Rep Power
    0

    Default

    Come on Eranga we all got that he/she is beginner.All I wish to show the way of learing java.That s all

    tOpach,

    Kind regards.
    A stitch in time saves nine:D

Similar Threads

  1. Replies: 22
    Last Post: 05-08-2008, 12:00 PM
  2. How to parse postfix arithmetic expressions
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 07:36 PM
  3. Stack push/pop/peek operations
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-29-2008, 09:03 AM
  4. String operations..
    By sireesha in forum New To Java
    Replies: 4
    Last Post: 12-14-2007, 02:04 AM
  5. Uses unchecked or unsafe operations message
    By Robbinz in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 10:56 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
  •