Decision Making in Java


All the programs in Java have set of statements, which are executed sequentially in the order in which they appear. However, there may arise some situations where programmers have to change the order of execution of statements based on certain conditions.

Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statements that are to be executed if the condition is true, or other statements to be executed if the condition is determined to be false.


Basic Flowchart for Decision Making

In Java, we have if statement and switch case for decision making which we are going to learn now.

Remember we used Ternary Operator ( ? : ) before, that is also called Conditional Operator and used for decision making.

We can use relational operators and logical operators to check result of condition which we already read before in operators section.

There are three types of if statements mostly used:

  • if
  • if... else
  • if... else if... else
Lets learn them in details.


Taking Input in Java Previous Next If Statement in Java