JAVA judgment
Word: if else otherwise
Single branch:
If (condition)
{
code block
}
If is a judgment statement. The code is formatted as above.
The inside of the If bracket is an expression. Executes a code block if the expression value is set. After executing The IF statement after the code.
If the IF condition is not true, then the code block is skipped to execute the IF statement code.
Example
Int a=10;
If (A==20)
{
a++;
System.out.println (a);
}
This is a simple if-judgment statement.
An If statement is called a single-branch judgment and can only perform if the IF condition is met.
Dual Branch:
If (condition)
{
code block
}
Else
{
code block
}
Interpretation: If the condition of the If is not true, then the code block within the else is executed.
subsequent code will continue to be executed after the else is executed.
Example :
String gender= "female ";
If (Gender.equals ("female "))
{
SYSTEM.OUT.PRINTLN ("yes"+gender);
}
Else
{
System.out.println ("Not a girl, a Boy");
}
This is a simple multi-branch judgment .
Two cases can be judged. One is for women, the other is not a female case.
Multi-Branch
A multi-branch is a nesting of If.
If (condition)
{
code block
}
else if (condition )
{
code block
}
else if (condition)
{
}
*********
The nested pattern is as follows. can satisfy a variety of conditions of judgment.
Example
int money=52;
if (money>=500)
{
System. out . println ("Buy Cadillac ");
}Else if(money>=100)
{
System. out . println ("buy passat ");
}Else if(money>=50)
{
System. out . println ("Buy Elantra ");
}Else if(money>=10)
{
System. out . println ("buy Austrian extension ");
}Else
{
System. out . println ("Buy Czech ");
}
Java Study Third if judgment