Decision Making Control in Java

In this chapter you will learn:decision-making-skills

  1. What is Decision Making in Java?
  2. What is If else Statement?
  3. What is switch case statement?
  4. Programming Example

What is Decision Making in Java?

Decision Making is a process in which a condition is evaluated and based on true/false result program gets direction to execute. Mainly If-else and switch case statements are responsible for decision making in Java.

What is If Else Statement?

If Else statement is primary decision making or branching control in Java. It tests a condition and return Boolean value (true or false) as output. If the output is true the if block executed otherwise else block gets executed. You can understand it with this picture.

Syntax

 

Programming Example

Output

D:\JavaProgram>javac IfElse.java

D:\JavaProgram>java IfElse
12 is greater than 10

D:\JavaProgram> __

 

What is Switch Case Statement in Java?

If you have to use multiple if else statement you can use switch case statement instead of it. In switch case statement there is a condition inside a switch and a list of condition in case. When a case condition matches with switch condition the program executes the particular case condition.

Syntax

Programming Example

Output

D:\JavaProgram>javac SwitchCase.java

D:\JavaProgram>java SwitchCase
Enter a Day Name in small letter:
saturday
It’s Saturday.. Party Night!!!

D:\JavaProgram> __

Summary

In this chapter you have learned what is decision making, if else block and switch case statement in Java. It is also known as branching in Java. In the next chapter you will learn how to get input from user in Java.


Leave a Reply

Your email address will not be published. Required fields are marked *