

{"id":6796,"date":"2018-01-30T12:49:33","date_gmt":"2018-01-30T12:49:33","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=6796"},"modified":"2026-05-09T16:37:58","modified_gmt":"2026-05-09T11:07:58","slug":"decision-making-in-java","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/","title":{"rendered":"Decision Making in Java (Syntax &amp; Example)"},"content":{"rendered":"<p>The Decision Making in Java topic is fairly self-explanatory. Decision-making means the action of making decisions and choosing the action plan accordingly.<\/p>\n<p>Consider a real-life example, you are driving a car on a road to a concert, and you see your fuel light flashing, you immediately decide that you will stop at the next petrol pump. But if the light had not blinked at all, you would have continued driving. Right? That is where you made a decision and planned your action.<\/p>\n<p>In this Java Tutorial, we will learn more about decision-making in Java.<\/p>\n<h3>Decision Making in Java<\/h3>\n<p>Decision-making in Java executes a particular segment of code based on the result of a Boolean condition. It is important because conditions define the flow of programs and the output of a particular program.<\/p>\n<p>Programming&#8217;s core idea of decision-making enables you to regulate how your code is executed depending on specific criteria. Decision-making statements can be implemented in Java in several ways, each with a distinct function.<\/p>\n<p>The most basic decision-making statement is the if statement. It evaluates a condition and executes a block of code only if the condition is true. Here&#8217;s the syntax:<\/p>\n<p>if (condition) {<br \/>\n\/\/ code to be executed if the condition is true<br \/>\n}<\/p>\n<p>The decision-making principles in Java chiefly consist of if-else statements, continue, break and switch statements. It decides the flow of the program control during the execution of the program.<\/p>\n<p><strong>There are 6 ways of exercising decision-making in Java:<\/strong><\/p>\n<ul>\n<li>if<\/li>\n<li>if-else<\/li>\n<li>nested-if<\/li>\n<li>if-else-if<\/li>\n<li>switch-case<\/li>\n<li>jump-break, continue, return<\/li>\n<\/ul>\n<h3>If Statement in Java<\/h3>\n<p>Java if statement is the simplest decision-making statement. It encompasses a boolean condition followed by a scope of code, which is executed only when the condition evaluates to true. However, if there are no curly braces to limit the scope of sentences to be executed if the condition evaluates to true, then only the first line is executed.<\/p>\n<p><strong>Syntax of the if statement in Java:<\/strong><\/p>\n<p>if(condition)<br \/>\n{<br \/>\n\/\/code to be executed<br \/>\n}<\/p>\n<p><strong>Flow diagram for Java if statement:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-for-if-statement.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78547\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-for-if-statement.jpg\" alt=\"If statement in java\" width=\"438\" height=\"593\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-for-if-statement.jpg 438w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-for-if-statement-222x300.jpg 222w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-for-if-statement-111x150.jpg 111w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/a><\/p>\n<p><strong>Example Java program to understand if statement:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.decisionmaking;\r\npublic class IfStatement {\r\n  public static void main(String[] args) {\r\n\r\n    System.out.println(\"Understanding if statements.\");\r\n    String s = \"DataFlair\";\r\n    if (s.equals(\"DataFlair\")) {\r\n      System.out.println(\"The string is DataFlair\");\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Understanding if statements.<br \/>\nThe string is DataFlair<\/div>\n<h3>if-else statement in Java<\/h3>\n<p>This pair of keywords is used to divide a program to be executed into two parts, one being the code to be executed if the condition evaluates to true, and the other being executed if the value is false.<\/p>\n<p>However, if no curly braces are given, the first statement after the if or else keyword is executed.<\/p>\n<p>if(condition)<br \/>\n{<br \/>\n\/\/code to be executed if the condition is true<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n\/\/code to be executed if the condition is false<br \/>\n}<\/p>\n<p><strong>Flow Diagram of Java if-else statement:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-of-if-else-statement.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78548\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-of-if-else-statement.jpg\" alt=\"if else statement in java\" width=\"652\" height=\"600\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-of-if-else-statement.jpg 652w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-of-if-else-statement-300x276.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-of-if-else-statement-150x138.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-of-if-else-statement-520x479.jpg 520w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/a><\/p>\n<p><strong>Java program to illustrate the use of the if-else statement:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.decsionmaking;\r\npublic class IfElseStatement {\r\n  public static void main(String[] args) {\r\n\r\n    System.out.println(\"Understanding if statements.\");\r\n    String s = \"DataFlairJava\";\r\n    if (s.equals(\"DataFlair\")) {\r\n      System.out.println(\"The string is DataFlair\");\r\n    }\r\n    else {\r\n      System.out.println(\"The string is not DataFlair\");\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The string is not DataFlair<\/div>\n<h3>Nested if Statements in Java<\/h3>\n<p>The nested if is similar to the nested loops we learned about in the previous chapters.<\/p>\n<p>The nested if statements are those that have further if-else statements inside them. The outer if statement is considered the entry checkpoint, which means that if the condition in the outer if statement is true, then only the inner if-else block gets executed. A program can have multiple if-else blocks inside an if statement. Look at the flow diagram of the program to get it clear.<\/p>\n<p><strong>Syntax of nested if statements in Java:<\/strong><\/p>\n<p>if(condition)<br \/>\n{<br \/>\n\/\/code to be executed<br \/>\nif(condition)<br \/>\n{<br \/>\n\/\/code to be executed<br \/>\n}<br \/>\n}<\/p>\n<p><strong>Flow diagram of Java nested if statement:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-a-nested-if-statement.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78549\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-a-nested-if-statement.jpg\" alt=\"nested if statement in java\" width=\"871\" height=\"605\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-a-nested-if-statement.jpg 871w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-a-nested-if-statement-300x208.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-a-nested-if-statement-150x104.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-a-nested-if-statement-768x533.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-diagram-a-nested-if-statement-520x361.jpg 520w\" sizes=\"auto, (max-width: 871px) 100vw, 871px\" \/><\/a><\/p>\n<p><strong>Java program to illustrate the use of nested if:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.decisionmaking;\r\npublic class IfNestedStatement {\r\n  public static void main(String[] args) {\r\n\r\n    System.out.println(\"Understanding if statements.\");\r\n    String s = \"DataFlair\";\r\n    if (s.equals(\"DataFlair\")) {\r\n      System.out.println(\"The string is DataFlair\");\r\n      if (s.charAt(0) == 'D') {\r\n        System.out.println(\"The first character is D! \");\r\n      }\r\n    }\r\n    else {\r\n      System.out.println(\"The string is not DataFlair\");\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Understanding if statements.<br \/>\nThe string is DataFlair<br \/>\nThe first character is D!<\/div>\n<h3>if-else-if Statements in Java<\/h3>\n<p>These statements are similar to the if-else statements. The only difference lies in the fact that each of the else statements can be paired with a different if condition statement. This renders the ladder as a multiple-choice option for the user. As soon as one of the if conditions evaluates to true, the equivalent code is executed, and the rest of the ladder is ignored.<\/p>\n<p><strong>Syntax of if-else-if statements in Java:<\/strong><\/p>\n<p>if<br \/>\n{<br \/>\n\/\/code to be executed<br \/>\n}<br \/>\nelse if(condition)<br \/>\n{<br \/>\n\/\/code to be executed<br \/>\n}<br \/>\nelse if(condition)<br \/>\n{<br \/>\n\/\/code to be executed<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n\/\/code to be executed<br \/>\n}<\/p>\n<p><strong>Flow Diagram of Java if-else-if statements:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-if-else-if-statements.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78550\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-if-else-if-statements.jpg\" alt=\"if else if statement in java\" width=\"731\" height=\"594\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-if-else-if-statements.jpg 731w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-if-else-if-statements-300x244.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-if-else-if-statements-150x122.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-if-else-if-statements-520x423.jpg 520w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/a><\/p>\n<p><strong>Java program to illustrate the use of if-else-if statements:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.decisionmaking;\r\npublic class IfElseIfStatement {\r\n  public static void main(String[] args) {\r\n\r\n    System.out.println(\"Understanding if statements.\");\r\n    String s = \"DataFlairPython\";\r\n    if (s.equals(\"DataFlair\")) {\r\n      System.out.println(\"The string is DataFlair\");\r\n    }\r\n    else if (s.equals(\"DataFlairJava\")) {\r\n      System.out.println(\"The string is DataFlair and course is Java\");\r\n    }\r\n    else if (s.equals(\"DataFlairPython\")) {\r\n      System.out.println(\"The string is DataFlair and the course is Python\");\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Understanding if statements.<br \/>\nThe string is DataFlair and the course is Python<\/div>\n<h3>Switch Statement in Java<\/h3>\n<p>The Java switch statement is a different form of the if-else-if ladder statements.<\/p>\n<ul>\n<li>This saves the hassle of writing else if for every different option.<\/li>\n<li>It branches the flow of the program to multiple points as and when required or specified by the conditions.<\/li>\n<li>It bases the flow of the program based on the output of the expression.<\/li>\n<li>As soon as the expression is evaluated, the result is matched with every case listed in the scope. If the output matches any of the cases mentioned, then the particular block is executed. A break statement is written after every end of the case block so that the remaining statements are not executed.<\/li>\n<li>The default case is written, which is executed if none of the cases is the result of the expression. This is generally the block where error statements are written.<\/li>\n<\/ul>\n<p><strong>Syntax of switch statement in Java:<\/strong><\/p>\n<p>switch(expression)<br \/>\n{<br \/>\ncase &lt;value1&gt;:<br \/>\n\/\/code to be executed<br \/>\nbreak;<br \/>\ncase &lt;value2&gt;:<br \/>\n\/\/code to be executed<br \/>\nbreak;<br \/>\ndefault:<br \/>\n\/\/code to be defaultly executed<br \/>\n}<\/p>\n<p><strong>Flow Diagram of Java switch statement:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-the-switch-statement.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78551\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-the-switch-statement.jpg\" alt=\"switch statement in java\" width=\"731\" height=\"594\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-the-switch-statement.jpg 731w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-the-switch-statement-300x244.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-the-switch-statement-150x122.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-of-the-switch-statement-520x423.jpg 520w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/a><\/p>\n<p><strong>Java program to illustrate the switch statement:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.decisionmaking;\r\nimport java.util. * ;\r\npublic class SwitchStatement {\r\n  public static void main(String[] args) {\r\n    Scanner sc = new Scanner(System. in );\r\n    System.out.println(\"You have two options of courses at DataFlair\");\r\n    System.out.println(\"1.Java\");\r\n    System.out.println(\"2.Python\");\r\n    System.out.println(\"Enter the number of course:\");\r\n    int ch = sc.nextInt();\r\n    switch (ch) {\r\n    case 1:\r\n      System.out.println(\"Congrats you have chosen Java!\");\r\n      break;\r\n    case 2:\r\n      System.out.println(\"Congrats you have chosen Python!\");\r\n      break;\r\n    default:\r\n      System.out.println(\"Wrong input!\");\r\n      break;\r\n    }\r\n\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">You have two options of courses at DataFlair<br \/>\n1.Java<br \/>\n2.Python<br \/>\nEnter the number of course:<br \/>\n2<br \/>\nCongrats you have chosen Python!<\/div>\n<h3>Jump Statements in Java<\/h3>\n<p>The Java jump statements are the keywords in Java which have a specific meaning and a specific action of disrupting the normal flow of the program. Some of them are:<\/p>\n<h4>1. Java break statement<\/h4>\n<p>The break statement in Java, as the name signifies, is useful to break out of the normal workflow of a program. We can use it to terminate loops, end cases of switch statements, and as a goto statement. Break statements, if used in a nested loop, terminate the innermost loop. The outermost loop still functions.<\/p>\n<p><strong>break statement as a goto statement in Java<\/strong><\/p>\n<p>If we mention a label after the break keyword, the control shifts to the end of the particular label scope. Java prohibits the use of goto statements because it encourages branched behaviour of programming. However, break labels function like goto statements.<\/p>\n<p><strong>Flowchart of Java break statement:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flowchart-of-break-statement.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78552\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flowchart-of-break-statement.jpg\" alt=\"break statement in java\" width=\"646\" height=\"575\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flowchart-of-break-statement.jpg 646w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flowchart-of-break-statement-300x267.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flowchart-of-break-statement-150x134.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flowchart-of-break-statement-520x463.jpg 520w\" sizes=\"auto, (max-width: 646px) 100vw, 646px\" \/><\/a><\/p>\n<p><strong>Java program to illustrate the use of the break keyword:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.decisionmaking;\r\nimport java.util. * ;\r\npublic class IfStatement {\r\n  public static void main(String[] args) {\r\n    for (int i = 0; i &lt; 10; i++) {\r\n      System.out.println(i);\r\n      if (i == 7) break;\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">0<br \/>\n1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5<br \/>\n6<br \/>\n7<\/div>\n<h4>2. Continue Statement in Java<\/h4>\n<p>The Java continue statement is useful for early iteration of a particular loop. Sometimes, rather than breaking out of a loop and halting it for good, we want to skip some iterations based on our requirements of a program. This results in the usage of continue statements.<\/p>\n<p><strong>Flow Diagram for Java continue statement:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-for-the-continue-statement.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78553\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-for-the-continue-statement.jpg\" alt=\"continue statement in Java\" width=\"644\" height=\"589\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-for-the-continue-statement.jpg 644w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-for-the-continue-statement-300x274.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-for-the-continue-statement-150x137.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Flow-Diagram-for-the-continue-statement-520x476.jpg 520w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/a><\/p>\n<p><strong>Java program to illustrate the use of the continue statement:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.decisionmaking;\r\nimport java.util. * ;\r\npublic class ContinueStatement {\r\n  public static void main(String[] args) {\r\n    for (int i = 0; i &lt; 10; i++) {\r\n\r\n      if (i == 7) continue;\r\n      System.out.println(i);\r\n\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">0<br \/>\n1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5<br \/>\n6<br \/>\n8<br \/>\n9<\/div>\n<p>Notice that 7 did not print because the entire iteration of it was skipped.<\/p>\n<h4>3. Return Statement in Java<\/h4>\n<p>The return keyword in Java, when executed by the compiler, returns control to the method it was called from. This is generally used in methods which are not of the void type and return some values. When the statement is executed, the return function returns to the caller method along with whatever variable is mentioned in the definition.<\/p>\n<p>However, if we mention <strong><a href=\"https:\/\/www.cis.upenn.edu\/~matuszek\/General\/JavaSyntax\/return.html\" target=\"_blank\" rel=\"noopener\">return statement<\/a><\/strong> in the main method, the compiler halts, and the program comes to an end. None of the statements below the return statement is executed by the compiler.<\/p>\n<p><strong>Syntax of return in Java:<\/strong><\/p>\n<p>return &lt;value&gt;;<br \/>\nor<br \/>\nreturn;<\/p>\n<p><strong>Java program to illustrate the use of the return statement in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.decisionmaking;\r\nimport java.util. * ;\r\npublic class ReturnStatement {\r\n  static int funcsqr(int x) {\r\n    return x * x;\r\n  }\r\n  public static void main(String[] args) {\r\n    for (int i = 0; i &lt; 10; i++) {\r\n\r\n      int y = funcsqr(5);\r\n      System.out.println(\"The value returned by the function is \" + y);\r\n      return;\r\n      \/\/ System.out.println(\"This statement would never get executed. \");\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The value returned by the function is 25<\/div>\n<h3>Summary<\/h3>\n<p>We learnt about decision-making in Java. These statements are very important in framing algorithms, and a clear concept of the decision statements is of utmost importance in programming. Java&#8217;s control flow statements can be combined to create more complex decision-making logic.<\/p>\n<p>For instance, you can nest an if-else statement within another if-else statement. This allows you to define a hierarchy of conditions, where the inner statement&#8217;s execution depends on the outcome of the outer statement. By effectively nesting control flow statements, you can model real-world scenarios with intricate decision-making processes within your Java programs.<\/p>\n<p><strong>Hope you enjoyed the article. Do share your feedback in the comment section!!!<\/strong><span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2046,&quot;href&quot;:&quot;https:\\\/\\\/www.cis.upenn.edu\\\/~matuszek\\\/General\\\/JavaSyntax\\\/return.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20220118022512\\\/https:\\\/\\\/www.cis.upenn.edu\\\/~matuszek\\\/General\\\/JavaSyntax\\\/return.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 00:00:57&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2025-12-16 12:44:14&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2025-12-23 05:54:35&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-02 05:35:07&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-07 10:36:37&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-28 06:32:37&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-03 05:35:00&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-09 04:51:57&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-16 01:17:20&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-26 07:37:45&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-04 19:15:33&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-09 02:28:24&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-14 14:38:08&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-17 15:16:08&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-23 21:03:18&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-29 09:40:25&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-05 00:20:06&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-09 06:05:25&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-13 23:38:35&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-21 08:08:34&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-26 03:08:27&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-03 13:42:36&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-07 05:07:20&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-16 18:00:14&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-22 19:37:41&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-29 04:44:58&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-02 21:18:23&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-09 10:54:45&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-12 18:45:14&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-12 18:45:14&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Decision Making in Java topic is fairly self-explanatory. Decision-making means the action of making decisions and choosing the action plan accordingly. Consider a real-life example, you are driving a car on a road&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":78546,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[2174,2966,20784,6453,6455,6456,7669,9043,14018],"class_list":["post-6796","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-break-statement-in-java","tag-control-statement-in-java","tag-decision-making-statement","tag-if-statement-in-java","tag-if-else-statements-in-java","tag-if-else-is-ladder-statements-in-java","tag-java-return-statement","tag-nested-if-statements-in-java","tag-switch-statement-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Decision Making in Java (Syntax &amp; Example) - DataFlair<\/title>\n<meta name=\"description\" content=\"The decision-making in Java is fairly self-explanatory. It means the action of making decisions and choosing the action plan accordingly.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Decision Making in Java (Syntax &amp; Example) - DataFlair\" \/>\n<meta property=\"og:description\" content=\"The decision-making in Java is fairly self-explanatory. It means the action of making decisions and choosing the action plan accordingly.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-30T12:49:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-09T11:07:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Decision-Making-in-Java-df.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Decision Making in Java (Syntax &amp; Example) - DataFlair","description":"The decision-making in Java is fairly self-explanatory. It means the action of making decisions and choosing the action plan accordingly.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Decision Making in Java (Syntax &amp; Example) - DataFlair","og_description":"The decision-making in Java is fairly self-explanatory. It means the action of making decisions and choosing the action plan accordingly.","og_url":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-01-30T12:49:33+00:00","article_modified_time":"2026-05-09T11:07:58+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Decision-Making-in-Java-df.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Decision Making in Java (Syntax &amp; Example)","datePublished":"2018-01-30T12:49:33+00:00","dateModified":"2026-05-09T11:07:58+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/"},"wordCount":1404,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Decision-Making-in-Java-df.jpg","keywords":["break statement in java","control statement in java","Decision making Statement","if statement in java","if-else statements in java","if-else-is ladder statements in java","Java Return Statement","nested-if statements in java","Switch Statement in Java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/decision-making-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/","url":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/","name":"Decision Making in Java (Syntax &amp; Example) - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Decision-Making-in-Java-df.jpg","datePublished":"2018-01-30T12:49:33+00:00","dateModified":"2026-05-09T11:07:58+00:00","description":"The decision-making in Java is fairly self-explanatory. It means the action of making decisions and choosing the action plan accordingly.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/decision-making-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Decision-Making-in-Java-df.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Decision-Making-in-Java-df.jpg","width":1200,"height":628,"caption":"Decision Making in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/decision-making-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Java Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/java\/"},{"@type":"ListItem","position":3,"name":"Decision Making in Java (Syntax &amp; Example)"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=6796"}],"version-history":[{"count":22,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6796\/revisions"}],"predecessor-version":[{"id":148270,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6796\/revisions\/148270"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/78546"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=6796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=6796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=6796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}