A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
Flow Control
Maxi Malahleha
Greenhorn
Joined: Dec 11, 2006
Posts: 28
posted
Aug 03, 2007 16:36:00
0
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: 35443
9
posted
Aug 03, 2007 17:14:00
0
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 ]
Android apps
–
ImageJ plugins
–
Java web charts
kishore Kumar Sangam
Ranch Hand
Joined: Jul 03, 2007
Posts: 34
posted
Aug 04, 2007 00:43:00
0
when you say x+=b*c then it means x = x + (b*c)
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Flow Control
Similar Threads
SCJP book by K&B q1 page 389
CS theory on a for loop...
Continue Statement Help
Operators
static variables
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter