Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

.

DISCUSSION

Java supports the usual logical conditions from mathematics:

It uses the following operators

Note the following examples

The if Statement
if (condition) {
// block of code to be executed if the condition is true
}
Example
int num1,num2;
num1=5;
num2=10;

if(num1<num2){
System.out.println(num1 + " is less than " + num2);
}

What do you think will be the output?

The if else statement


if (condition) {
// block of code to be executed if the condition is true
}
Else{
//block of code to be executed if the statement is false
}

Example
int num1,num2;
num1=15;
num2=10;

if(num1<num2){
System.out.println(num1 + " is less than " + num2);
}
else
{
System.out.println(num2 + " is less than " + num1);
}

The if else if else statement


if (condition1) {
// block of code to be executed if the condition1 is true
}
else if (condition2) {
// block of code to be executed if the condition2 is true
}
else if(condition3) {
// block of code to be executed if the condition3 is true
}
else{
//block of code to be executed if all the conditions above is false
}

Example
int num1,num2;
num1=10;
num2=10;

if(num1<num2){
System.out.println(num1 + " is less than " + num2);
}
else if (num2<num1){
System.out.println(num2 + " is less than " + num1);
}
else{
System.out.println(num1 + " and " + num2 + " is equal");
}

You might also like