Page 54 of 55 FirstFirst ... 44452535455 LastLast
Results 1,061 to 1,080 of 1093

Thread: Quiz Time

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

    Default

    Nobody? I'll wait a few more hours and then I'll simply dump a link to the solution (from Bloch's and Gafter's book).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default

    Quote Originally Posted by JosAH View Post
    Nobody? I'll wait a few more hours and then I'll simply dump a link to the solution (from Bloch's and Gafter's book).
    I waited two more days and still nothing; the answer is here (it's problem #9, the other puzzles are fun too).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #1063
    ashok bhagat is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Ok, here is another one. :)

    Java Code:
    public class MyQuizTwo {
        
        public static void main(String[] args) {
            if("String".trim() == "String".trim())
                System.out.println("Yes");
            else
                System.out.println("No");
    
    
        }
    }
    Guess the answer, not in an IDE ;)
    error in if condition

  4. #1064
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,813
    Rep Power
    19

    Default

    Quote Originally Posted by ashok bhagat View Post
    error in if condition
    Well, no.

    And that's answering a Quiz question from over 2 years ago...:)

  5. #1065
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    print "yes"

  6. #1066
    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

    Of course, it's very old quiz. So here is a quick one to refresh.

    In the following code, is it finally code executed or not?

    Java Code:
     try {
            if (condition) {
                 while (true)
            } 
            else {
                system .exit(1):
            }
    }
    finally {
        //  Clean the code
    }

  7. #1067
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    In the following code, is it finally code executed or not?
    it is not executed if condition is true,
    but would be executed if condition is false.

    .. i mean, if we didn't get compile errors from the missing ";" after while. and the "system" typo.

  8. #1068
    ashok bhagat is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    if condition is true then it will go in continuous loop

  9. #1069
    ashok bhagat is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    m i right?:confused:

  10. #1070
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,813
    Rep Power
    19

    Default

    It's never run. You're either in a permanent loop, or you exit the program.
    An exit() call is not the same as an exception.

  11. #1071
    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

    I think it's better to send my comments over here.

    Quote Originally Posted by Tolls View Post
    It's never run. You're either in a permanent loop, or you exit the program.
    An exit() call is not the same as an exception.
    Vote for this. :)

  12. #1072
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Long time no quiz.
    Java Code:
    public class Main {
    
       public static void main(String[] args) {
          int n = 0;
          for (int i = 0; i <= Integer.MAX_VALUE; i++) {
             n = i;
          }
          System.out.println(n);
       }
    }
    What will this print, and why?

    db

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

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Long time no quiz.
    Java Code:
    public class Main {
    
       public static void main(String[] args) {
          int n = 0;
          for (int i = 0; i <= Integer.MAX_VALUE; i++) {
             n = i;
          }
          System.out.println(n);
       }
    }
    What will this print, and why?

    db
    I had already forgotten about this thread; thanks for resurrecting it; fun! I won't answer this one ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #1074
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    It won't print anything, because it's impossible for i to ever exceed Integer.MAX_VALUE and terminate the loop. Instead, the next value after Integer.MAX_VALUE is -Integer.MAX_VALUE-1.

  15. #1075
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by toadaly View Post
    It won't print anything, because it's impossible for i to ever exceed Integer.MAX_VALUE and terminate the loop. Instead, the next value after Integer.MAX_VALUE is -Integer.MAX_VALUE-1.
    You win ... the right to post the next quiz!! :p

    db

  16. #1076
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    I was afraid of that, ok, the following is inspired by a recent post here. Why won't this compile?

    Java Code:
    public class Green<T extends Day> implements OnHoli<T> {
      public Vector<Onholi<T>> crankIt = new Vector<OnHoli<T>>();
    }
    
    public interface AnyDay extends Day {
    }
    
    public interface Holler extends OnHoli<AnyDay> {
    }
    
    public class BlueOctober implements Holler {
    }
    
    new Green<Day>().crankIt.add(new BlueOctober());

  17. #1077
    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 Darryl.Burke View Post
    Quote Originally Posted by toadaly View Post
    It won't print anything, because it's impossible for i to ever exceed Integer.MAX_VALUE and terminate the loop. Instead, the next value after Integer.MAX_VALUE is -Integer.MAX_VALUE-1.
    You win ... the right to post the next quiz!! :p

    db
    Yes. But what we should do in such a case. Say I want to traverse all the possibilities there.

  18. #1078
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by Eranga View Post
    Yes. But what we should do in such a case. Say I want to traverse all the possibilities there.
    Use a long for the loop counter. And if you need to loop up to or beyond Long.MAX_VALUE, use a BigInteger and a supercomputer.

    db

  19. #1079
    123pompidou is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default Ridiculous attempt to get others to do homework

    Moderator edit: Ridiculous attempt to get others to do homework deleted.
    Last edited by Fubarable; 05-18-2011 at 09:05 PM.

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

    Default

    Quote Originally Posted by 123pompidou View Post
    Moderator edit: Ridiculous attempt to get others to do homework deleted.
    As good tradition dictates: your turn now ;-)

    kindest regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 54 of 55 FirstFirst ... 44452535455 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
  •