• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to write java program for getting condition of both if and else will be executed.  RSS feed

 
saravanakumar rajendran
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi in an interview they asked me to do a coding for both if and else statement needs to work .
can any one tell me how to write logic for this
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Its impossible. The basic if - else condition statement is either of the block will be executed.

seems he is testing the basic understanding ...
 
saravanakumar rajendran
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks srinivas,
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can achieve that using switch but not using if.
[ September 19, 2006: Message edited by: Chetan Parekh ]
 
fred Joly
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Please don't laugh to loud...I'm quite certain you can find sometimes
this kind of code with just a little bit of disguise
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Joly, nice work around!!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'd change it so that there was a

condition = !condition;

in both the if and the else... that way, it doesn't matter which you start with.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!