{"id":2310,"date":"2017-06-11T11:23:20","date_gmt":"2017-06-11T11:23:20","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2310"},"modified":"2021-03-21T07:08:33","modified_gmt":"2021-03-21T07:08:33","slug":"java-program-for-nested_if_statement","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/java-program-for-nested_if_statement\/","title":{"rendered":"Java program for nested if statement"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>We use nested if-else statements when multiple decisions are involved in the java program. We can nest many if statements or if-else statements in the program based on the decisions. We can use one if or if-else statement inside another if\/if-else statement<\/p>\n<h3>Syntax<\/h3>\n<p>The sample syntax of nested if statement in the simplest form is :<\/p>\n<p><strong>If (Boolean_expression 1)<\/strong><\/p>\n<p><strong>{<\/strong><\/p>\n<p><strong>\/\/Executes when the Boolean expression 1 is true<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If (Boolean_expression 2)<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Executes when the Boolean expression 2 is true<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/strong><\/p>\n<p><strong>}<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>Java Program<\/h3>\n<p>We will write a simple java program to show the syntax usage of the nested if in a Java program.<\/p>\n<pre>import java.util.Scanner;\r\n\r\n\/***********************************************************\r\n * NestedIfStatement.java \r\n * @program : Java program using nested if loop \r\n * @web : www.testingdocs.com \r\n * @version : 1.0 \r\n * ************************************************************\/\r\npublic class NestedIfStatement { \r\n\tpublic static void main(String[] args) {\r\n\t\tScanner console= new Scanner(System.in);\r\n\t\tSystem.out.print(\"Enter Student score in a subject:= \");\r\n\t\tint score = console.nextInt();\r\n\t\tif(score &gt;= 40) { \r\n\t\t\tSystem.out.println(\"Student got Pass mark.\");\r\n\t\t\tif(score &gt;= 70) { \r\n\t\t\t\tSystem.out.println(\"Student got distinction score.\");\r\n\t\t\t} \r\n\t\t} \r\n\t} \r\n}\r\n\r\n<\/pre>\n<p>In this program, two variables a &amp; b are initialized to some arbitrary values. Using nested if statement the output of the variables is printed.<\/p>\n<h3>Program Output<\/h3>\n<p>Enter Student score in a subject:= 75<br \/>\nStudent got Pass mark.<br \/>\nStudent got distinction score.<\/p>\n<h3>Screenshot<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5638\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Nested-If-Statement-Java-Program.png\" alt=\"Nested If Statement Java Program\" width=\"1295\" height=\"879\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Nested-If-Statement-Java-Program.png 1295w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Nested-If-Statement-Java-Program-300x204.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Nested-If-Statement-Java-Program-1024x695.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Nested-If-Statement-Java-Program-768x521.png 768w\" sizes=\"auto, (max-width: 1295px) 100vw, 1295px\" \/><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"><\/pre>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-2310\" data-postid=\"2310\" class=\"themify_builder_content themify_builder_content-2310 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Introduction We use nested if-else statements when multiple decisions are involved in the java program. We can nest many if statements or if-else statements in the program based on the decisions. We can use one if or if-else statement inside another if\/if-else statement Syntax The sample syntax of nested if statement in the simplest form [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2310","post","type-post","status-publish","format-standard","hentry","category-java-programs","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=2310"}],"version-history":[{"count":4,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2310\/revisions"}],"predecessor-version":[{"id":19755,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2310\/revisions\/19755"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}