aspose file tools*
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
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: 39548
    
  27
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 - updated with new look and Ping home screen widget
kishore Kumar Sangam
Ranch Hand

Joined: Jul 03, 2007
Posts: 34
when you say x+=b*c then it means x = x + (b*c)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Flow Control
 
Similar Threads
static variables
SCJP book by K&B q1 page 389
CS theory on a for loop...
Continue Statement Help
Operators