Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
System.out.println(0xffff); //ans???
kanna nedumaram
Greenhorn
Posts: 5
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class A {
static int m(int i) {
System.out.print(i + ",");
return 0;
}
public static void main (
String
[] args) {
int i = 0;
i = i++ + m(i);
System.out.print(i);
}
}// how ans 1,0
it should be 1,1
any way i value is icrmented know?/i++ only = 0
Vishnu Prakash
Ranch Hand
Posts: 1026
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
++i adds 1 to i first then uses the new value of i as the value of expression.
i = i + 1;
result = i;
return result;
i++ uses the current value of i as the value of expression first, then adds 1 to i.
result = i;
i = i + 1;
return result;
In your example
i = i++ + m(i);
i++ = 0 then i value is incremented to 1
so m(i) is m(1)
in method m you get the result 1 and you return 0.
as in " i = i++ + m(i);"
i++ is already 0 and m(i) also returns 0 the result is 0
which is why the output is 1 and 0
Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1
-
JSTL Tag Documentation
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
The i++ operator
why??
can anybody explain the flow
choosing method
doubt in explanation dam mock question
More...