Page 29 of 55 FirstFirst ... 19272829303139 ... LastLast
Results 561 to 580 of 1093

Thread: Quiz Time

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

    Default

    AngryBoy is correct, and he even schooled me.

    I knew that all String literals are stored in a String cache. What I *didn't* know is that *any* String can be added to that cache using String.intern().

    When a String is internalized, then the runtime guarantees that only one instance of the object will be used. This can speed up comparisons, but it has to be done manually, it has a lot of initial overhead, and the cache is only so large.

  2. #562
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default Quiz2

    Are you guys giving away bananas this time too?

    here's my turn:
    What is the console output of the following?
    Java Code:
    /** What is the output of the following?
     *  Do this in your head,
     *  [B]WITHOUT[/B] using [B]IDE, paper, or fingers[/B].
     */
    public class FunQuiz {
      public static void main(String[] args){
        for(int n=0,m=0; n < 8; ++n,m++){
          for(; n < m; n++,++m){
            System.out.print(n+m++);
          }
        }
      }
    }
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

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

    Default

    Noithing? because n is greater than m and never enters the second "for" loop.

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

  4. #564
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    o...
    CJSLMAN... how can you Observe that...

    n++, ++n, ++m, m++ are last steps of for loops,
    n, m both add 1 after that round of looping
    Last edited by mtyoung; 01-31-2009 at 02:50 AM.

  5. #565
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    i saw that, mtyoung, b4 you edited it. ;)

    chris got it right. i was trying to throw you off.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

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

    Steve why are you start another thread same as the other. No point. Please better to stick with one. It's much better I think, since more discussions are going on a single thread lots of members can useful it.

    I'm waiting for your comments to merge those two threads.

  7. #567
    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 angryboy View Post
    Are you guys giving away bananas this time too?

    here's my turn:
    What is the console output of the following?
    Java Code:
    /** What is the output of the following?
     *  Do this in your head,
     *  [B]WITHOUT[/B] using [B]IDE, paper, or fingers[/B].
     */
    public class FunQuiz {
      public static void main(String[] args){
        for(int n=0,m=0; n < 8; ++n,m++){
          for(; n < m; n++,++m){
            System.out.print(n+m++);
          }
        }
      }
    }
    Yes, you cannot see any output here, as CJSLMAN says.

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

  9. #569
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Talking The Pterodactyl Protectorate

    Quote Originally Posted by angryboy View Post
    It's much better to write: unsigned int n; rather than place if statements all over the codes to check for (n<0).
    ?

    Java has no unsigned because of it's protectorate. ( note: I undersand where you are at on this - that's not exactly the issue ) so anyway no unsigned bytes is sorta like a dyna sour swooping clumsily from several hundred feet. Bytes, as computer memory, are not signed. Numerics are, we have ( for the code I posted ) an issue in that the calls are to an un-signed character ( which is antecedent code for what is ......

    Never mind.


    @Steve: ( I take a day off, and the next thing I know, we have a religious war ) This is not religion, this is computer science. Writing memory by blowing out enums at the front of the code is not a humanities issue, is it? Don't assume that Java would provide protection, if they did - why is / are database drivers loaded the way they are?

    I don't know what is completely normal in the C++ world, nor in Java.

    Java is supposed to project you from these sorts of mistakes by throwing exceptions but if they were going full boogie the IEEE floating point remainder problem and several others would have been fixed awhile back. I think you need to let angryboy lead here, I am busy with an OCR in Java and in way over my head. I can come around and keep him taking the point, you can keep you coffe like in your avatar and wait to see if angryboy can make the ansi C commitee come up with a raw data format other than void*

    60+% of the market is actually device driven controllers of some kind - such issues as we are discussing here are endemic to business world programming, where there's money involved and the cozen are constantly at it keeping nescience enshrined as recherché plackart obtaining obsequious xeniality in insipid compliance with adiaphorous lethologica.

    @angryboy: Okay, I got him pumped for you. Now defend unsigned int in a Java discussion forum. Steve's been at it awhile, I expect the cannonical recitals about something or other. Let's hear the cannon ( look it up in O.E.D. or Random House New Collegiate ) then backfire with const keyword binds to the left. Watch his mind move across the mainstream over to the defensive side. While he's thrashing, figure some datatype definitely bound for graphics ops.

    I'll keep you between the rails on the stuff you do not know - just focus on One Sole Goal, not One Soul Goal.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  10. #570
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Both sides presented valid points. Which brings the question most of us has already asked: Why doesn't java throw integer overflow exceptions?
    btw, steve, can we merge the two quizes together?
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  11. #571
    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 angryboy View Post
    Both sides presented valid points. Which brings the question most of us has already asked: Why doesn't java throw integer overflow exceptions?
    I'm not get you. Java handle the overflow as we discuss past few post.

    Quote Originally Posted by angryboy View Post
    btw, steve, can we merge the two quizes together?
    Actually I can do that, but we need to know about Steve's thoughts on this. He's the starter of that thread. It's really nice thread actually, same as this one.

  12. #572
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    I'm not get you. Java handle the overflow as we discuss past few post.
    Sorry, hadn't read the past few post yet. actually i'm still on page 2. haha. As you can tell, its a looooog thread.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  13. #573
    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

    Ya, it's the longest thread we have in our community. But the interesting this is, that's the only thread a newbie can look at and learn a lot in a short period of time.

  14. #574
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    Default

    Java Code:
            Integer i11 = 1;
            Integer i12 = 1;       
            Integer i21 = 201;
            Integer i22 = 201;
            System.out.println(i11 == i12);        
            System.out.println(i21 == i22);
    Output of this ?

  15. #575
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    ProjectKaiser ...
    it is an old question la

    as i remember... -128 <= Integer <= 127 will return true in above condition

  16. #576
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default quiz

    One from my side.......

    DO NOT COMPILE...........AND......RUN.

    What will be the output?? will it compile??

    Java Code:
    import java.util.*;
    
    public class SortMe {
        public static void main(String args[]) {
            SortedSet<StringBuffer> s = new TreeSet<StringBuffer>();
            s.add(new StringBuffer("Red"));
            s.add(new StringBuffer("White"));
            s.add(new StringBuffer("Blue"));
            System.out.println(s.first());
        }
    }

  17. #577
    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

    For me you get a compile error. You've added two string buffer objects into the set. Set cannot compare them for ordering.

  18. #578
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    For me you get a compile error. You've added two string buffer objects into the set. Set cannot compare them for ordering.
    Eranga......you are bit closer........

    it will compile...........there will be a runtime exception.......can you explain the same.
    sanjeev,संजीव

  19. #579
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    @AngryBoy--unsigned int? Is this something new?
    that's c code.

    ProjectKaiser ...
    it is an old question la

    as i remember... -128 <= Integer <= 127 will return true in above condition
    actually, i suggested him to put it in cauze i didn't know it was asked already. This really is a long thread, mostly fill w/ conversations. I'm gona try and make a "Table of Contents" as i read through it.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  20. #580
    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 sanjeevtarar View Post
    Eranga......you are bit closer........

    it will compile...........there will be a runtime exception.......can you explain the same.
    Oops I've miss that. Comparing cannot do that at compile time, must be runtime.

Page 29 of 55 FirstFirst ... 19272829303139 ... 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
  •