DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Chicago
    Posts
    24

    Can someone explain why this happens?

    sample quiz question
    suppose that the following variable declarations have been made:
    int i = 0, int k = 0; String s = "@"; Give the exact output produced by the following code fragments:
    (a)
    System.out.print(i==3); // I know this won't work
    (b)
    System.out.println("Ans: "+(j++)+(++j)+(j++)+(++J); // I don't understand why it gives 0224 and not 1234
    (c)
    for (; k<3; k++) {
    System.out.print(s);
    s = s+s;
    }
    System.out.println(s); // I need to know why it returns 15 @ signs and not seven
    Thanks for the help
    Last edited by Mcody2; 11-01-2005 at 11:34 PM.

  2. #2
    Join Date
    Sep 2005
    Location
    istanbul / Turkey
    Posts
    133
    System.out.print(i==3); // I know this won't work
    this will work , it will produce boolean value ( equals false . )
    this expression means " is ( i == 3 ) true ? "

    (j++)+(++j)+(j++)+(++J)
    j++ means do something with j, later increase it.
    ++j means increase j, later do something with it.

    for (; k<3; k++) {
    System.out.print(s);
    s = s+s;
    }
    after 3 steps :
    s = @ (1) -->@@ (2)-->@@@@(4) all of them printed..
    ( now s =@@@@@@@@(8) )
    and s printed too.
    1+2+4+8 = 15 @

Similar Threads

  1. DB2 Visual Explain
    By jim pias in forum Database
    Replies: 0
    Last Post: 03-11-2003, 05:26 PM
  2. Can someone explain what is happening with this code...
    By Robert Tedesco in forum VB Classic
    Replies: 14
    Last Post: 05-05-2002, 06:00 AM
  3. Explain Plan does not provide output
    By shafiq in forum Database
    Replies: 3
    Last Post: 03-31-2002, 12:22 AM
  4. Can some one explain Recordset Page!
    By Johan in forum ASP.NET
    Replies: 0
    Last Post: 03-03-2002, 07:20 AM
  5. Explain >>> in details?
    By ken in forum Java
    Replies: 2
    Last Post: 02-06-2001, 03:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links