{"id":2024,"date":"2017-05-29T14:33:00","date_gmt":"2017-05-29T14:33:00","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2024"},"modified":"2022-03-12T14:17:39","modified_gmt":"2022-03-12T14:17:39","slug":"java-program-for-largest-of-three-numbers","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/java-program-for-largest-of-three-numbers\/","title":{"rendered":"Java program for largest of three numbers"},"content":{"rendered":"<h3>Program Description<\/h3>\r\n<p>Write a java program to find the largest of three numbers. In the program, we will prompt the user to enter three numbers. Using the <strong>if-else-if<\/strong> clause ladder, we will decide the largest number out of the three numbers.\u00a0\u00a0<\/p>\r\n<h2>Tools Used:<\/h2>\r\n<ul>\r\n<li>JDK\u00a0<\/li>\r\n<li>Eclipse IDE<\/li>\r\n<\/ul>\r\n<h3>Largest of Three Numbers Program<\/h3>\r\n<p>Create a new Java class and code the program logic. The program prompts the user to enter the input. Three variables are used to store the user input. In-built Java Scanner class is used to read the user input.\u00a0<\/p>\r\n<p>The program takes a series of decisions using the if-else-if ladder control statements. The flow of the program is controlled by these statements.\u00a0<\/p>\r\n<h2>Eclipse IDE Setup<\/h2>\r\n<p>Some steps and instructions to create a Java application on Eclipse IDE:<\/p>\r\n<ul>\r\n<li>Create Java Project in Eclipse<\/li>\r\n<\/ul>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/create-a-new-java-project-in-eclipse\/\">https:\/\/www.testingdocs.com\/create-a-new-java-project-in-eclipse\/<\/a><\/p>\r\n<ul>\r\n<li>Create Java Package in Eclipse<\/li>\r\n<\/ul>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/create-java-package-in-eclipse-ide\/\">https:\/\/www.testingdocs.com\/create-java-package-in-eclipse-ide\/<\/a><\/p>\r\n<ul>\r\n<li>Create Java Class in Eclipse<\/li>\r\n<\/ul>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/create-a-new-java-class-in-a-project\/\">https:\/\/www.testingdocs.com\/create-a-new-java-class-in-a-project\/<\/a><\/p>\r\n<ul>\r\n<li>Run Java Project in Eclipse<\/li>\r\n<\/ul>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/run-java-project-in-eclipse\/\">https:\/\/www.testingdocs.com\/run-java-project-in-eclipse\/<\/a><\/p>\r\n<h2>Java Code<\/h2>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import java.util.Scanner; \r\n\r\n\/**************************************************\r\n * LargestOfThreeNumbers.java\r\n * @program   \t: LargestOfThreeNumbers Java Program. \r\n * @web        \t: www.TestingDocs.com\r\n * @version     : 1.0\r\n **************************************************\/\r\n\r\npublic class LargestOfThreeNumbers {\r\n  public static void main(String[] args) {\r\n    int a, b, c; \r\n    Scanner sc = new Scanner(System.in); \r\n    System.out.print(\"Please enter a :=\");\r\n    a = sc.nextInt(); \r\n    System.out.print(\"Please enter b :=\");\r\n    b = sc.nextInt(); \r\n    System.out.print(\"Please enter c :=\");\r\n    c = sc.nextInt(); \r\n    if(a &gt; b &amp;&amp; a &gt; c) {\r\n      System.out.println(\"a i.e (\"+ a + \") is the largest number.\"); \r\n    } else if(b &gt; a &amp;&amp; b &gt; c) { \r\n      System.out.println(\"b i.e (\"+ b + \") is the largest number.\"); \r\n    } else if(c &gt; a &amp;&amp; c &gt; b) { \r\n      System.out.println(\"c i.e (\" + c + \") is the largest number.\");\r\n    } else {\r\n      System.out.println(\"Given three numbers are not distinct\");\r\n    } \r\n    sc.close(); \r\n  } \r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n<h3>Screenshot<\/h3>\r\n<p>Screenshot of the program in the IDE.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5647\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Largest-of-Three-Numbers-Java-program-1.png\" alt=\"Largest of Three Numbers Java program\" width=\"1241\" height=\"882\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Largest-of-Three-Numbers-Java-program-1.png 1241w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Largest-of-Three-Numbers-Java-program-1-300x213.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Largest-of-Three-Numbers-Java-program-1-1024x728.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Largest-of-Three-Numbers-Java-program-1-768x546.png 768w\" sizes=\"auto, (max-width: 1241px) 100vw, 1241px\" \/><\/p>\r\n<h3>Program Output<\/h3>\r\n<p>Save the program and execute the program. Test and verify the output of the program.\u00a0<\/p>\r\n<p>Please enter a :=15<br \/>Please enter b :=6<br \/>Please enter c :=22<br \/>c i.e (22) is the largest number.<\/p>\r\n<h3>Enhancements<\/h3>\r\n<p>The program expects or assumes that the user will enter proper input. There is not exception handling in the program. We can further enhance the program to incorporate exception handling with <strong>try-catch<\/strong> blocks.<\/p>\r\n<p>&#8212;<\/p>\r\n<h2>Java Tutorials<\/h2>\r\n<p>Java Tutorial on this website: <strong><a href=\"https:\/\/www.testingdocs.com\/java-tutorial\/\">https:\/\/www.testingdocs.com\/java-tutorial\/<\/a><\/strong><\/p>\r\n<p>For more information on Java, visit the official website :<\/p>\r\n<p><strong><a href=\"https:\/\/www.oracle.com\/in\/java\/\" rel=\"noopener\">https:\/\/www.oracle.com\/in\/java\/<\/a><\/strong><\/p>\r\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-2024\" data-postid=\"2024\" class=\"themify_builder_content themify_builder_content-2024 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Program Description Write a java program to find the largest of three numbers. In the program, we will prompt the user to enter three numbers. Using the if-else-if clause ladder, we will decide the largest number out of the three numbers.\u00a0\u00a0 Tools Used: JDK\u00a0 Eclipse IDE Largest of Three Numbers Program Create a new Java [&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-2024","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\/2024","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=2024"}],"version-history":[{"count":10,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2024\/revisions"}],"predecessor-version":[{"id":21759,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2024\/revisions\/21759"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}