{"id":2245,"date":"2017-06-05T09:24:04","date_gmt":"2017-06-05T09:24:04","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2245"},"modified":"2021-03-21T07:11:02","modified_gmt":"2021-03-21T07:11:02","slug":"write-a-java-program-to-find-the-maximum-element-in-an-array","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/write-a-java-program-to-find-the-maximum-element-in-an-array\/","title":{"rendered":"Write a Java Program to find the maximum element in an array"},"content":{"rendered":"<h3>Problem Description<\/h3>\n<p>Write a Java Program to find the maximum element in an array. We will declare an array with some numbers. Loop each element in the array to find the maximum element in the given array.<\/p>\n<h3>Java Program<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/\/********************************\r\n\/\/MaxInArray.java\r\n\/\/********************************\r\n\r\npublic class MaxInArray {\r\n  \/\/main method\r\n  public static void main(String[] args) {\r\n    int maxValue= Integer.MIN_VALUE;\r\n    int[] arr = {2, 6, 18, 9, 56, 44, 63, 22, 76, 28}; \/\/ declare an array of numbers\t\r\n\r\n    for (int i = 0; i &lt; arr.length; i++) {\r\n      if(arr[i] &gt; maxValue) {\r\n        maxValue = arr[i];\r\n      }\r\n    }\r\n    System.out.print(\"The maximum element in the array is= \" + maxValue); \/\/output max number\r\n  }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>Program Output<\/h3>\n<p>The maximum element in the array is= 76<\/p>\n<h3>Screenshot<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2262\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Maximum-element-in-an-array-Java-Program.png\" alt=\"Maximum element \" width=\"1758\" height=\"1032\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Maximum-element-in-an-array-Java-Program.png 1758w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Maximum-element-in-an-array-Java-Program-300x176.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Maximum-element-in-an-array-Java-Program-1024x601.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Maximum-element-in-an-array-Java-Program-768x451.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Maximum-element-in-an-array-Java-Program-1536x902.png 1536w\" sizes=\"auto, (max-width: 1758px) 100vw, 1758px\" \/><\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-2245\" data-postid=\"2245\" class=\"themify_builder_content themify_builder_content-2245 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Problem Description Write a Java Program to find the maximum element in an array. We will declare an array with some numbers. Loop each element in the array to find the maximum element in the given array. Java Program \/\/******************************** \/\/MaxInArray.java \/\/******************************** public class MaxInArray { \/\/main method public static void main(String[] args) { int [&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-2245","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\/2245","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=2245"}],"version-history":[{"count":3,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2245\/revisions"}],"predecessor-version":[{"id":19758,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2245\/revisions\/19758"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}