• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Flow Control

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you say x+=b*c then it means x = x + (b*c)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic