Professional Documents
Culture Documents
Conditional Statements and Operators
Conditional Statements and Operators
-----------------
Arithematic operators [+,-,*, /, %]: These are used for performing arithematic
operations.
--------------------------------------
1)/--->Quotient
2)%--->Reminder
Relational operators [<,>,<=,>=,==,=,!=]: These are used for comparing the values.
---------------------------------------
These are applicable for boolean but not for integral values. if(5&&3)--
>CompileError
Bitwise operators[&(AND),|(OR)]:
-------------------------------
5&3
5->0101
3->0011
--------
0001 -->1
Unary operators[++,--]:
-----------------------
conditional statements
----------------------
if statement is used to test the condition.
-------------------------------------------
It checks boolean condition: true or false.
-------------------------------------------
There are various types of if statement in Java
------------------------------------------------
simple if
---------
if(condition)
{
code to be executed
}
if-else
-------
if-else statement also tests the condition. It executes the if block if condition
is true otherwise else block is executed
if(condition)
{
code
}
else
{
code
}
if-else-if
-----------
if-else-if statement executes one condition from multiple statements
if(condition1)
{
else if(condition2)
{
}
else if(condition3)
{
else
{
}
switch case : switch statement executes one statement from multiple conditions.
------------
The case values must be unique. In case of duplicate value, it renders compile-time
error.
switch(expression){
case value1:
code
case value2:
code
default:
-----------------------------------------------------------------------------------
-------------------------------------------------------------------