Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Flow Control

 
Maxi Malahleha
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
kishore Kumar Sangam
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you say x+=b*c then it means x = x + (b*c)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic