This is the fifth lecture of the Learn Java lecture series. In this you’ll learn about conditions in Java. We will be working with if condition and conditioning with switch statement in java.

Same as before create a new class and call it conditions.

new class in java

Before we start with if condition here are some standard signs used to compare two integers in almost every language.

If Condition:

If condition is simple if(condition) {…code inside of if…}.

Else is used to concatenate if conditions. It is also used to give a default condition if none of the condition is true.

If condition with while loop:

Let’s count to 30 and print something whenever a number is divisible by 5.

Here is an exercise for you. Change newInt/5 to newInt%5==0. Right now it is dividing it and % means calculating mode. Here is the output of that:

output of a java if condition program

Switch Statement:

The syntax of switch statement in java is:



Tags : how to writ switch statement in javaif statement in javaswitch statement in java
Chaudhary Talha

The author Chaudhary Talha

I'm an iOS developer by profession and UI/UX designer by passion. All my tutorials are based on my personal experiences and whenever I learn something new I share it with the world.