Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
JavaDecisionMaking
Decision making structures have one or more conditions to be evaluated or tested by the
program, along with a statement or statements that are to be executed if the condition is
determined to be true, and optionally, other statements to be executed if the condition is
determinedtobefalse.
Following is the general form of a typical decision making structure found in most of the
programminglanguages:
Javaprogramminglanguageprovidesfollowingtypesofdecisionmakingstatements.Clickthe
followinglinkstochecktheirdetail.
Statement
Description
if
Anifstatementconsistsofaboolean
expressionfollowedbyoneormorestatements.
statement
Anifstatementcanbefollowedbyan
optionalelsestatement,whichexecuteswhen
thebooleanexpressionisfalse.
if...else
statement
nested
statements
switch
statement
if
Youcanuseoneiforelseifstatementinside
anotheriforelseifstatement(s).
Aswitchstatementallowsavariabletobe
testedforequalityagainstalistofvalues.
http://www.tutorialspoint.com/java/java_decision_making.htm
1/2
6/11/2016
JavaDecisionMaking
The?:Operator:
We have covered conditional operator ? : in previous chapter which can be used to
replaceif...elsestatements.Ithasthefollowinggeneralform:
Exp1?Exp2:Exp3;
WhereExp1,Exp2,andExp3areexpressions.Noticetheuseandplacementofthecolon.
Todeterminethevalueofwholeexpression,initiallyexp1isevaluated
Ifthevalueofexp1istrue,thenthevalueofExp2willbethevalueofthewholeexpression.
Ifthevalueofexp1isfalse,thenExp3isevaluatedanditsvaluebecomesthevalueofthe
entireexpression.
http://www.tutorialspoint.com/java/java_decision_making.htm
2/2