Consider the following method:
static int mx(int s){
for(int i=0; i<3; i++){
s = s + i;
}
return s;
}
and the following code snippet:
int s = 5;
s += s + mx(s) + ++s;
System.out.println(s);
What will it print?
EXPLANATION:
s += (expression) will be converted to s = s + expression. So the given expression will become:
s = s + s + mx(s) + ++s;
s = 5 + 5 + mx(5) + 6;
s = 5 + 5+ 8 + 6;
s = 24;
My Question: Where come from 8?
About Question enthuware.ocpjp.i.v11.2.1290 :
Moderator: admin
-
- Posts: 1
- Joined: Tue Jun 30, 2020 12:19 pm
- Contact:
-
- Site Admin
- Posts: 10054
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.1290 :
8 is the value returned by the method invocation mx(5).
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 38 guests