Monday, December 19, 2022

If else condition statement | java tutorial for beginners

 In this tutorial you we will learn about how to use if else condition statement . we will use good example to understand how if else statement should created and to use it. If you would like to video tutorial on Java If else conditional statement, below is link in Hindi and English language.

Java If else video tutorial in English 

                                    Java If else video tutorial in Hindi

lets create class in Java, As we can see we have created class IfElse and inside we have created non static method and we provide name as myIfElse and  we use void since we are not returning anything. After that we typed bracket and in curly brace we will type our logic.

Scenario:  If it will rain , instruct do not go out side and if it will not rain then print lets go out side . Make Java program using IF Else statement . 

So lets make program . First we created variable and datatype as boolean. we set it as true it means , there is rain.

Now we type if, and we will type bracket next to it, we will provide condition inside. We set isRain == true. when we use = means we are assigning or setting value and if we use == it means we are comparing .  So if there is rain we will run block of code ,which block of code ? it will print "Do not go outside". And if we set our variable to false then it will run "Lets go out side"

Since we set as true , it will print "Do not go outside code" . Lets check output. Click on Run and check our output.

If you change isRain to false it will run else block.  Hope you understood concept if else in java. If you started learning java , make this kind of simple and easy program it will be fun .  If you want more video tutorial click on this link and watch .

java switch statement | Java Tutorial For Beginners

 Switch statement is alternative and more cleaner way to write code if we have more than two options. we can use else if, this is better way...