Page 48 of 55 FirstFirst ... 384647484950 ... LastLast
Results 941 to 960 of 1093

Thread: Quiz Time

  1. #941
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,513
    Blog Entries
    7
    Rep Power
    20

    Default

    Here's another one: as we all know (or should know) the following construct doesn't generate any code at all:

    Java Code:
    if (false) {
       // code here isn't generated
    }
    This is ideal for 'conditional compilation' and for debugging purposes. But why does the following fail during compilation then?

    Java Code:
    while (false) {
       // code here isn't generated
    }
    kind regards,

    Jos

  2. #942
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    It'll say unreachable code. Just like when you code after a return or a break.

    I... don't know why the if (false) does compile, sorry :P
    I die a little on the inside...
    Every time I get shot.

  3. #943
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    LOL !
    I've got one,
    Java Code:
    public class QUIZ {
    
        public static void main(String[] args) {
            String busDriver = "You are the bus driver.";
            int peopleOnBus = 50;
            int peopleCameOn = 47;
            int peopleGotOff = 3;
            
            peopleOnBus = peopleOnBus + peopleCameOn - peopleGotOff;
            
        }
    }
    What is the bus driver's name?

  4. #944
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    His name: Peter

  5. #945
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by Fubarable View Post
    His name: Peter
    Yay! You WIN !

  6. #946
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Fubarable's secret identity is revealed!
    The Java Tutorial. Read it.

  7. #947
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,513
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Supamagier View Post
    It'll say unreachable code. Just like when you code after a return or a break.

    I... don't know why the if (false) does compile, sorry :P
    Let's wait for other replies a bit ...

    kind regards,

    Jos

  8. #948
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    Quote Originally Posted by JosAH View Post
    Let's wait for other replies a bit ...

    kind regards,

    Jos
    JosAH, are you commenting your code in if(false) manner? ;)

    The code manner allows compilation but it is commonly used as for rendering code obsolete commenting. I think it is my answer :)

    But, JosAH, I would recommend you to use documented comments like a
    Java Code:
    //
    or
    Java Code:
    /**/
    instead :D

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

  10. #950
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by JosAH View Post
    Let's wait for other replies a bit ...

    kind regards,

    Jos
    It's the if that's showing special behavior isn't it? To allow "conditional compilation". The while body is unreachable because
    Quote Originally Posted by JLS
    The contained statement is reachable iff the while statement is reachable and the condition expression is not a constant expression whose value is false.
    JLS 14.21

  11. #951
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,513
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by r035198x View Post
    It's the if that's showing special behavior isn't it? To allow "conditional compilation". The while body is unreachable [... ]
    Yup, that's the answer; the 'if (false) ...' construct is explicitly defined that way by the JLS (I don't have it handy now so no ref). Otherwise there wouldn't exist a 'conditional compilation' feature.

    kind regards,

    Jos

  12. #952
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Talking

    Quote Originally Posted by Fubarable View Post
    His name: Peter
    And how old is the bus driver then ? :rolleyes:

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

  14. #954
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Yea, ask everything about the busdriver so we can stalk Peter! *-)

    :)
    I die a little on the inside...
    Every time I get shot.

  15. #955
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    I'm confusing too much then.
    No need to be confused. It is all a good old English riddle :D

    Specially for Eranga WikiAnswers - You are the bus driver the first stop a man and his dog get on the bus along with a girl licking a lollipop the next stop a boy and his dad get on wearing his baseball clothes what is the drivers name

    :D

  16. #956
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Question

    OK, guys, if you really come up with riddles here is another one ;)

    Can you answer the question:

    Why Mickey Mouse did go to outer space? :rolleyes:

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

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

    Default

    Quote Originally Posted by Webuser View Post
    OK, guys, if you really come up with riddles here is another one ;)

    Can you answer the question:

    Why Mickey Mouse did go to outer space? :rolleyes:
    I got you this time, you remind my preschool.

    http://www.howtodrawguide.com/wp-con...and-pluto0.jpg

  19. #959
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Thumbs up

    Quote Originally Posted by Eranga View Post
    I got you this time, you remind my preschool.

    http://www.howtodrawguide.com/wp-con...and-pluto0.jpg
    My...my... Do you like watching US cartoons in Sri Lanka?

    +1 for Eranga :D

  20. #960
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Question

    here is another one. :rolleyes:
    Answer the question...

    What begins with T, ends with T and has T in it?

Page 48 of 55 FirstFirst ... 384647484950 ... LastLast

Similar Threads

  1. Hello, first time here.
    By ludragon in forum Introductions
    Replies: 2
    Last Post: 01-03-2008, 05:03 AM
  2. Help pls with a quiz
    By saytri in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 06:09 AM
  3. Time method
    By carderne in forum New To Java
    Replies: 5
    Last Post: 11-05-2007, 09:34 AM
  4. DataObject with the time given by me
    By garinapavan in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 06:33 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
  •