Conditional Statements if elseif else Example in Java
In this class, We discuss Conditional Statements if elseif else Example in Java.
The reader should have basic knowledge of the execution of if elseif statements. Click Here.
Example:
Write a program to suggest diabetic medicine based on the below table.
Based on the blood glucose level suggestion is made.
Blood glucose — Suggestion
Greater than 90 – consult a doctor
Between 80 and 90 – Take 20 MG tablet
Between 70 and 80 – Take 15 MG tablet
Between 60 and 70 – Take 10 MG tablet
Below 60 – Stop using the tablet.
In our last class, we discussed when to use if elseif statements.
If we need to check a sequence of conditions, we go with the if elseif statement.
The below diagram shows the complete code.
The variable bg is used to take the blood glucose value.
The conditions are checked one after another.
If any statement satisfies the condition, the code block will be executed.
Output: Take a 15 MG tablet.