This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Flow Control Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Flow Control" Watch "Flow Control" New topic
Author

Flow Control

Maxi Malahleha
Greenhorn

Joined: Dec 11, 2006
Posts: 28
Hi

please explain the out put to this code.

public class FlowControl {
public int control(int x){
int a = 1;
a+= x;
if((x > 4) && (x < 10)){

a+= 2*x;

}else if(x <= 4){
a+= 3 * x;

} else {
a+= 4 * x;
}
a+= 5 * x;

return a;
}
public static void main(String[] args) {
FlowControl o = new FlowCOntrol();
System.out.println("FC(34) is:" + o.control(34));
}
}

output is 341

Why not 171
why not 307
why not 205
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41147
    
  45
I'll give you a hint: x is 34 -and does not change- so which of the "if" tests will succeed?
[ August 03, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
kishore Kumar Sangam
Ranch Hand

Joined: Jul 03, 2007
Posts: 34
when you say x+=b*c then it means x = x + (b*c)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Flow Control
 
Similar Threads
CS theory on a for loop...
SCJP book by K&B q1 page 389
static variables
Operators
Continue Statement Help