-
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.
-
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++ 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
-
By jim pias in forum Database
Replies: 0
Last Post: 03-11-2003, 05:26 PM
-
By Robert Tedesco in forum VB Classic
Replies: 14
Last Post: 05-05-2002, 06:00 AM
-
By shafiq in forum Database
Replies: 3
Last Post: 03-31-2002, 12:22 AM
-
By Johan in forum ASP.NET
Replies: 0
Last Post: 03-03-2002, 07:20 AM
-
Replies: 2
Last Post: 02-06-2001, 03:21 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks