{"id":1392,"date":"2022-03-03T19:18:43","date_gmt":"2022-03-03T19:18:43","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1392"},"modified":"2022-03-03T19:18:43","modified_gmt":"2022-03-03T19:18:43","slug":"program-to-reverse-the-array","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/program-to-reverse-the-array\/","title":{"rendered":"Program to reverse the Array"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Program to reverse the array<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\npublic class Example\n{\n   public static void main(String args&#91;])\n   {\n\tint counter, i=0, j=0, temp;\n\tint number&#91;] = new int&#91;100];\n\tScanner scanner = new Scanner(System.in);\n\tSystem.out.print(\"How many elements you want to enter: \");\n\tcounter = scanner.nextInt();\n\n\t\/* This loop stores all the elements that we enter in an \n\t * the array number. First element is at number&#91;0], second at \n\t * number&#91;1] and so on\n\t *\/\n\tfor(i=0; i&lt;counter; i++)\n\t{\n\t    System.out.print(\"Enter Array Element\"+(i+1)+\": \");\n\t    number&#91;i] = scanner.nextInt();\n\t}\n\n\t\/* Here we are writing the logic to swap first element with\n\t * last element, second last element with second element and\n\t * so on. On the first iteration of while loop i is the index \n\t * of first element and j is the index of last. On the second\n\t * iteration i is the index of second and j is the index of \n\t * second last.\n\t *\/\n\tj = i - 1;     \n\ti = 0;         \n\tscanner.close();\n\twhile(i&lt;j)\n\t{\n  \t   temp = number&#91;i];\n\t   number&#91;i] = number&#91;j];\n\t   number&#91;j] = temp;\n\t   i++;\n\t   j--;\n\t}\n\n\tSystem.out.print(\"Reversed array: \");\n\tfor(i=0; i&lt;counter; i++)\n\t{\n\t   System.out.print(number&#91;i]+ \"  \");\n\t}       \n   }\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>How many elements you want to enter: 5\nEnter Array Element1: 11\nEnter Array Element2: 22\nEnter Array Element3: 33\nEnter Array Element4: 44\nEnter Array Element5: 55\nReversed array: 55  44  33  22  11<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Program to reverse the array Output:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[404],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1392"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1392"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1392\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}