Posts Tagged tutorial 3
Java Tutorial 3 – If Else Statements
If else is exactly as same as If else in C/C++.
Lets do this in New Class to create a new Class don’t create new project. click on package above your class and select new –> java class and give name to the class anything you want then hit enter.
Add this code to new created class and you might get idea.
- create main() method.
- defined an int and a Scanner object for user input (refer to previous tutorial)
Here i have not used {} after if() because if there is only 1 line in the if(){ … } it is optional to do {}.
you can try it by removing {} from else also.
You can add more den 1 condition in if statement by separating them with &&(and) ||(or)
else if() is also the same and u can try it at your own.
(what the fridge ! is it Home work !)
Again Doubts are invited.
Have a nice 1, Peace.

