{"id":77,"date":"2015-07-20T13:09:33","date_gmt":"2015-07-20T10:09:33","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=77"},"modified":"2015-07-22T23:17:54","modified_gmt":"2015-07-22T20:17:54","slug":"find-the-maximum-of-three-numbers","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=77","title":{"rendered":"Find the maximum of three numbers"},"content":{"rendered":"<p><strong>Task<\/strong>. Were given three real numbers [latex]x[\/latex], [latex]y[\/latex], [latex]z[\/latex]. Find [latex]\\max (x, y, z)[\/latex].<\/p>\n<h1>Tests<\/h1>\n<table border=\"2\">\n<tbody>\n<tr>\n<th>Input<\/th>\n<th>Output<\/th>\n<\/tr>\n<tr>\n<td>4 3 8<\/td>\n<td>\u00a08<\/td>\n<\/tr>\n<tr>\n<td>0 179 45<\/td>\n<td>179<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>Solution<\/h1>\n<p>With if-statement<\/p>\n<pre class=\"lang:java decode:true\">import java.util.*;\r\nclass Main{\r\npublic static void main (String[] args) throws java.lang.Exception {\r\nScanner s = new Scanner(System.in);\r\nwhile(s.hasNextInt()){\r\nint x = s.nextInt();\r\nint y = s.nextInt();\r\nint z = s.nextInt();\r\n\r\nif(x &gt; y &amp;&amp; x &gt; z){\r\nSystem.out.println(\"Maximum number is: \" + x);\r\n}\r\n\r\nelse if(y &gt; z &amp;&amp; \u00a0y &gt; x){\r\nSystem.out.println(\"Maximum number is: \" + y);\r\n}\r\n\r\nelse{\r\nSystem.out.println(\"Maximum number is: \" + z);\r\n}\r\n\r\n\/\/by using Math method from Java library \r\nint max =Math.max(Math.max(x,y),z);\r\nSystem.out.println(\"Max number is: \" + max);\r\n}\r\n\r\ns.close();\r\n}\r\n}<\/pre>\n<p>Code refactoring<\/p>\n<pre class=\"lang:java decode:true \">&lt;pre class=\"lang:java decode:true \"&gt;import java.util.*;\r\n\r\nclass Main{\r\n     public static void main (String[] args) throws java.lang.Exception {\r\n          Scanner s = new Scanner(System.in);\r\n          int x = s.nextInt();\r\n          int y = s.nextInt();\r\n          int z = s.nextInt();\r\n\r\n          \/\/solution with Java Library method\r\n          System.out.println(Math.max(Math.max(x,y),z));\r\n\r\n          \/\/solution with code refactoring without IF statement\r\n          System.out.println(x &gt; y &amp;&amp; x &gt; z ? x : y &gt; z &amp;&amp; z &gt; x ? y : z); \r\n \r\n         s.close();\r\n     }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Task. Were given three real numbers [latex]x[\/latex], [latex]y[\/latex], [latex]z[\/latex]. Find [latex]\\max (x, y, z)[\/latex]. Tests Input Output 4 3 8 \u00a08 0 179 45 179 Solution With if-statement import java.util.*; class Main{ public static void main (String[] args) throws java.lang.Exception { Scanner s = new Scanner(System.in); while(s.hasNextInt()){ int x = s.nextInt(); int y = s.nextInt(); &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=77\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":166,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[17,22,18],"jetpack_featured_media_url":"https:\/\/java.mazurok.com\/wp-content\/uploads\/Animals___Cats_Three_little_kitten_042340_.jpg","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/77"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":6,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions\/148"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/media\/166"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}