reverse an array in java using for loop

Solutions on MaxInterview for reverse an array in java using for loop by the best coders in the world

showing results for - "reverse an array in java using for loop"
Finn
09 Jan 2019
1// Reverse an array in java using for loop
2public class ReverseArrayUsingForLoop 
3{
4   public static void main(String[] args) 
5   {
6      int[] arrNumbers = new int[]{2, 4, 6, 8, 10};  
7      System.out.println("Given array: ");  
8      for(int a = 0; a < arrNumbers.length; a++)
9      {
10         System.out.print(arrNumbers[a] + " ");
11      }
12      System.out.println("Reverse array: ");
13      // looping array in reverse order
14      for(int a = arrNumbers.length - 1; a >= 0; a--) 
15      {  
16         System.out.print(arrNumbers[a] + " ");  
17      }
18   }
19}
Bronagh
10 Jan 2018
1int length = array.length;
2		for(int i=0;i<length/2;i++) {
3			int swap = array[i];
4			array[i] = array[length-i-1];
5			array[length-i-1] = swap;
6		}
7or
8Collections.reverse(Arrays.asList(array)); 
Walter
19 Apr 2016
1var array = ['a','b','c','d','e','f','g']
2var j = array.length 
3
4for(var i = 0; i < array.length ; i++){
5    console.log(array[j])
6    j=j-1 }
7
8    /*
9
10var j holds value of the array's number of values so every time in the loop it decrements by 1 making the 
11function print a backwars array
12
13
14
15    */
Claudia
23 Mar 2018
1import java.util.Scanner;
2public class Example
3{
4   public static void main(String args[])
5   {
6	int counter, i=0, j=0, temp;
7	int number[] = new int[100];
8	Scanner scanner = new Scanner(System.in);
9	System.out.print("How many elements you want to enter: ");
10	counter = scanner.nextInt();
11
12	/* This loop stores all the elements that we enter in an 
13	 * the array number. First element is at number[0], second at 
14	 * number[1] and so on
15	 */
16	for(i=0; i<counter; i++)
17	{
18	    System.out.print("Enter Array Element"+(i+1)+": ");
19	    number[i] = scanner.nextInt();
20	}
21
22	/* Here we are writing the logic to swap first element with
23	 * last element, second last element with second element and
24	 * so on. On the first iteration of while loop i is the index 
25	 * of first element and j is the index of last. On the second
26	 * iteration i is the index of second and j is the index of 
27	 * second last.
28	 */
29	j = i - 1;     
30	i = 0;         
31	scanner.close();
32	while(i<j)
33	{
34  	   temp = number[i];
35	   number[i] = number[j];
36	   number[j] = temp;
37	   i++;
38	   j--;
39	}
40
41	System.out.print("Reversed array: ");
42	for(i=0; i<counter; i++)
43	{
44	   System.out.print(number[i]+ "  ");
45	}       
46   }
47}
Linus
24 Jan 2019
1
2    for (int i = aList.size() - 1; i >= 0; i--) {
3        String s = aList.get(i);
4    }
5
Dianne
15 Apr 2020
1for (int counter = myArray.length - 1; counter >= 0; counter--) {
2
queries leading to this page
reverse arra javawrite a program to reverse an array in javareverse an array java 5dprint an array in reverse for loopjava method to reverse an array for loopprint array in reverse order javajava reverse for each loopprint the reverse order of the arrayiterate backwards on array javareverse a n array javarev array javato reverse elements of an array in javahow to print an array in reverse order in javareverse elements of array in javahow to reverse a array in javaarray reverse in java inbuilt functionhow to invert an array in javaflip int 5b 5d 5b 5d arrayprint array elements in reverse order in javahow to take values in array and return in opposite order javafunction reversearray 28collection 29reverse array int in javaarrays rev in javareverse aray javahow to print an array in reverse order javajava array reverse programreverse array javareverse an array with begin and end in javahow to reverse an array without using another array in javareverse for loop javajava reverse order of elments in arrayhow to put an array in reverse orderjava code to return reverse an arrayjava array reverse sortprint array reversereversing a array in javareverse forloop in javaint array reverse javareverse function for arrays in javahow to reverse decrement for loop javaprint out array in reversereverse inplace array in java java reverse array functionreversing array javarecursive reverse string javareverse elements in array javajava read array backwardshow to reverse a array javareverse values of an array in javamethod to reverse array in javahow to print a array in reverse order in javamake a reverse for loop javajava program to print array elements in reverse orderjava loop in reversereverse array elements in javareverse 10 element array reverse javajava backward loopinvert java arrayarrays reverse javahow to reverse elemtns in an array javaareversearray method that accepts an array as parameter 2c reverse an array and return the reversed array programme to print an array in reverse order in javareverse in java arraysjava code to reverse int arrayprint array in reverse order in javareverse array in java functionhow to reverse the elements in an arrayjava return reverse arrayreverse a array javareverse array java libraryhow to reverse print an arrayinverting a java arrayjava reverse two dimensional arrayhow to reverse a array in javaprinting an array in reverserevert an array javareverse int array javahow to reverse iterate through array values in javaiterate through array backwards javahow to reverse the array elements in javahow to take array reverse in javajava for loop loop array backwardsefficient way to reverse an array in javareverse aray in javajava arrays reversereverse array in havahow to reverse in javareverse 28 29 in javahow to print elements of an array in reverse orderhow to print an array in reverse javahow to reverse an array in java inbuilt functionprinting an array backwards in javahow to reverse an array in java in placemethod to reverse an array in javamethod to reverse a array in javaefficient java code to reverse array elementsreverse java arraujava code to reverse an arrayreverse arry in place javajava to take array from user and reverse in javaprint an array in reverse order javahow to reverse array using for loopinvert array java array reverse java 8array reverse sort in javareverse a integer array in javahow to turn a set of strings into an array and then reverse that arrayreverse number in array javacreate java function to reverse arrayprint matrix backwardsreverse arrray javahow to reverse order an array in javareverse function in java for arrayarray reverse in java methodjava for reverse loopreverse elements in an arraybest way to reverse array javavalues of array in reverse orde in javaarray reverse javareverse array using only one variable in javajava array reverse orderhow to reverse an array method in javajava backwards for loophow to print an array backwards in javafor loop to reverse array javareverse array java code easy codereverse elements in an array javasort array backwards javaarrays reverse function in javaprint array backwardsreverse in java arrayjava reverse arrayreverse in array javaprint array elements in reverse orderhow to reverse number in array in javaprogram in java to read n number of values in an array and display in reverse orderjava util arrays reversehow to return an array in reverse order javareverse an array in java functioncode for reversing an array in javajava reverse an int arrayreverse a list in javareverse an array of integersreversing an array n 5e2java loop backwardshow to reverse an array of integers in java 2f 2f reverse an array in java using for loophow to reverse array data in javareverse order of an array in javahow to reverse array elements in javaprogram or reversing array in javahow to return a reverse array in javajava print array in reversereversing an array javahow to reverse loop through the array in javafastest way to reverse elements in array javajava inverting arrayjava invert arrayreverse an array in java using for loophow to read an array in reverse orderhow to print reverse for loop in javareverse array using java 27how to reverse an array in ajavajava reverse arrrayhwo to print array in reversereverse array and return array in javareverse print array javaflip array javafor loop array in reversehow to display array in reverse order javafor loop start at end or front java 3fjava reverse int arraywrite a java program to reverse a given array using methodreverse the array in jaavreverse array elements in java using reverse functionjava how to reverse aarrayhow to reverse the order of an array javahow to print reverse array in javareverse in javahow to reverse a arrray in javahow to reverse an array in java reverse or backwards for loop javareverse loop javaarray in reverce in javaarrays sort reverse in javaarray reverse in java utility functionprinting an array in reverse order javaclass container reversing arrayprinting array reverse in javareverse an array in java using inbuilt functionreverse a array in javahwo to reverse content of an array in androidhow to reverse elements in an arrayreverse an array in java using while loopreturn reverse array javarevering an arrayhow to print an array in reversemethod to reverse n array in javaprogram to print array in reverse orderjava reverse arraydequehow to reverse loop in javaprint array in reverse best solutionreverse a number in java using while loopwrite a java program to reverse an array backwards for loop javareverse array havareverse for loop 3djavareverse array function in javahow to reverse integer array in javahow to iterate backwards javareverse sort java arraysimilarly 2c write a method reversearray 28also same type 29 which returns an array of that length with the numbers from 1 to n in reverse order so 2c reversearray 285 7d should return an array containing 7b5 2c4 2c3 2c2 2c1 7d function to reverse array in javareverse an arr javajava array rverse functionarray reverse java methodreverse array in java libraryreverse of integer array in java using java 8 collectionsreverse array iusing for loop javaprint elements of array in reverse order javaprint all elements of an array in java in reverse ordrdisplay array values in reverse order in javaarray reverse order javajava reverse for loopreverse an integer array javahow to reverse complete array java inbuitcode segments that reads 10 and display in reverse order in array javaprint array in reversejava reversearrayhow to reverse the order of an int array in javahow to print from an array in reverse orderreverae array in hjavareverse array in jvareverse inbuilt function for array in javareverse and array in javarevers array javaprogramme to reverse an array in javaarrays sort in java reversehow to reverse decrement for loop javareverse an array in java using keywordreverse values in array javahow to reverse complete array javahow to display elements in an array in the reverse orderreverse java arr iterationjava print array in reversjava program to reverse an array reverse an array in ajavabackward loop javaarray reverse in javahow to do a reversed arrayjava for reverse orderreverse numbers in an array javaloop array in reverse javainverti array javaarrays reverse jvaprint array in function in reversereverse arrya in javajava iterate backwards through arrayreverse function for array in javahow do you reverse an array in place in java 3freverse of array in javareverse arraysliar javareverse printing java for loopreverse an array in place javareverse arraay in javajava reverse looprevert array javajava sort a array reversehow to reverse array javareverse an int array in javareverse an integer array in javause a function to print an array in reversearray reverse utility in javareverse array in java 8reverse method for array in javaflipping array javajava util arrays reversehow to reverse an int array in javaprogrammiz reverse array in javahow do you print an array backwardsreverse array java codereverse function in java to reverse arrayreverse the srting using loop in javareverser array javastatic int 5b 5d reverse array 28int 5b 5d a 29 c 23print string array backwards javahow to print the reverse of an array in javafor each loop in java for reverse listprint elements in array in reverse orderfodisplay array in reversehow to print out for loop in reverse javareverse number using for loop in javareverse order of integer array in javareverse sort an array javahow do you reverse an array in place in javareverse an array in javahow to reverse int 5b 5d array in javahow to iterate backwards with a while loop in javareverse array integer in java using for loophow to reverse a arry in javahow to reverse data in array in javajava reverse method arrayreverse array java for loopinteger array reverse in javareverse integers of arrayjava program to reverse an array ihow to print array from end to beggining javareverse integer in pythonfor loop in reverse order in javareversing arrays in javareverse a number in java in arrayarray reverse in javahow to sort array reverse in java 3freverse an array in java methodreverse method in javareverse foreach javaarray reverse javarevers array in javaprint reverse of an array javahow to return reverse order javarverse array in havareverse 28 29 for array in javahow to reverse an array in java without using reverse functionhow to display array backwards in javacreate a bew array reversedhow to write reverse string array for each loop in javareverse arrray in java how to reverse an array in java inbuiltreverse a string array javareverse number in java using for looparr reverse javahow to print array elements in reverse order javajava reverse arraysreverse array in java inbuiltallintitle 3areverse an array in java using for loophow to make array reverse method in javafor loop to print in ereverse orderarray string reverse in javahow to reverse the array in java reverse 28 29 in javareverse order array javaarrays reverse in javahow to print an arrays elements in reversereversing array in javahow to print array in revese ordereverse a number in java using for loopjava reverse string arrayjava reverse arrazreverse array elements javaeverse an array javareverse une array javareverse array order javajava reverse array loopreverse an array using function in javareverse array in parts javahow to write a reverse array method jvareverse a sub array in javahow to do reverse array in javainvert a array javaarray loop to display the reverse of all number in the array javaprinting elements of array in reversehow to reverse array in java programhow to reverse the order in an array in javareverse enhncaed loop in javareverse arr javareversing elements in an array javaarray reverse java libraryreverse the array in java methodreverse java function arrayreverse array jaavaprint array last to firstinvert an array javadisplay the array elements in reverse order javareversing arrsy javahow to reverse a statement in javareverse the array javahow to reverse order of an array in javahow to reverse an arrayreverse array method in javareverse array program in jvaaprint reverse array in javahow to reverse for loop javaprint array in reverse order for loophow to print array in reverse order in javato reverse a array in javaforeach from reverse javahow to reverse elements in an array javaarrays reverse javahow to iterate backwards through a java arrayhow to reverse array in java in builthow to reverse an array in java builtinrevese a array in javareverse method arrays javatraverse through array until find value javahow to display array in reverse orderproblem to reverse an array in javajava reverse sort arrayhow to reverse a number in java using for loopprint an array in reverse orderprint elements of array in reverse javahow to reverse an array using for loop in javahow to reverse an array in java using inbuilt functionprint reverse number in array javareverse sort array javafor reverse order javatake array from user and reverse in javajava reverse array elementshwo to reverse array in javahow to return an array in reverse in javaarray reverse javaarrays reverse 28 29 in javacontents of an array backwards using a loophow to reverse a integer array in javajava loop array backwardsarray traverse reverse in javareverse for loop in javajava for loop reverseprint reverse arrayjava reverse array without built in functionreverse array javafunction matrix reverse in java reverse in javareverse ana array javareverse array string in javawhile loop to traverse an arryalsit in javajava revers arrayreversing operation in array in javareverse array shortcut javainbuilt method to reverse a array in javaprint array inverse how to put reversed array in new array javareverse the array elements in javahow to solve a reverse array in javahow reverse array javaprogram to reverse array in javacreate reverse array javaprint reverse array feom user in javadeclare and implement a function called reverseprint you should accept a single array of char values as your only argument 2c and print that array backwards 2c one character on each line your function should return the length of the array as an int how do you reverse the elements in an array 3fhow to print array backwards in javalogic to reverse an array in javaflip int arrayprint string array in reverse order javaprint reverse array javajava array command to reverse a numberreverse the given array in javahow do we reverse an array in javareverse array in java using methodbest way to reverse array in javareverse array java 3dsorted map in javahow to reverse a int in java using for loopcontents of an array backwards using a while loophowto reverse array withoutcollectionsbackwards arrays javareverse an int array javareverse array algorithm javareverse order an array javahow to display an array in reverse order in javaprint array of array elements in reverse orderreverse array sort javareverse of an array in javajava reverse array methodreverse integer array in javafunction that print the array elements in reverse orderreversing an array in javajava reverse forreverse the digit of array and concatenate javahow to print an array in reverse orderhow to reverse an integer array in javajava inbuilt methods to revese an arrayprogram to reverse an array in javareverse java array intreverse java arrayreverse a arrayin ajvabuilt in function to reverse array in javawrite the reverse method array javaarray reverse function in javareverse method in array in javaarray reverse java codereverse order of array javafilp integer arrayreverse number without loop in javamethod in java to reverse arrayjava function to reverse an arrayreverse array indexing javareverse array of javaprint array in reverse orderjava reverse array public methodhow to reverse the items in an arrayhow to reverse order an arrayjava how to reverse an arrayarray operations in java reversejava program to get an array from user and reversehow to reverse the contents in an array javaexample of reversing array in javais there inbilt function to reverse the array in javareverse array method javareverse array java gfghow to output an array backwards with doubles javaarray reverse function injavarevers order array javajava reverse for loop for arrayhow to loop backwardsprint each element of a array in reverse javareverse array in java using for loophow to print array backwardreverse an array from start and end in javaiterate through array reverse javaarrays reverse javarevers array integer in javajava reverse array orderhow to print array in reversehow to print array in reverse javareverse an array in javajava program to print reverse of an arrayrevese an array in javahow to print array in reverse orderreverse arry javaprint reverse array from user in javahow to print array in reverse order java how to reverse an array java 5carrays reverse in javago through array backwards javaiterate backwards javaarray reverse loopreverse array number in javahow to reverse iterate in javaprint the array in reverse javareverse inside for javaflip an array javareverse method array javahow to reverse an integer from the array in javaprint an array backwards in javareversed for loop javahow to invert an arrayarrays reverse order javareverse array in place in javahow to reverse the order of an arraystring reverse in java using for loopreverse a 1d array in javahow to reverse array in jvaajava program to reverse value of array elementsreverse an array in java programhow to reverse a n array in javareverse the array in javareverse order of array in javahow to display the elements of an array in reverse javareturn array in reverse order javajava reverse an arrayhow to reverse a array in jaavareverse an array javareverse sort array in javaprint array in reverse order java revser arrayjava sort array reverseprint array in reverse order in java using for each loopjava arrays reversewap in java program to reverse a number using looparray iterate over array in reverse javahoe to reverse the array in javahow to flip an array in javajava method reverse arrayreversing an arrar in javaprogram in java to read n number of values in an array and display in reverse order using arraylistjava array reversereverse array function javahow to print an array backwardsprinting to an array in reverse in java with while loopreversing int 5b 5d array in javamethod reverse the array in javaturning an array into two strings and reverse ithow to reverse array in javarevrsing an array in javaarrays reverse sort in javahow to output an array backwards javareverse all elements of array javareverse print of an arrayjava inbuilt function to reverse the arrayjava array reverserevere an array in javahow to print a reverse array in javaarray reverse 28 29 javareversearray javareverse loop in javareverse array in javajava arrays reverse sorthow to invert an array javaprinting array reversereverse array in javareverse array sort in javahow to print an array in java reversearray reverse method in javahow to print array backwardsarray java reversejava reverse array integersprinting array in reverse order in javajava reverse methodwrite a java program to reverse an array of integer values reverse java int arrayreverse an arrayarray element in reverse javareverse array element in javauser reversal algorithm in javaarrays reversereverse arr in javahow to access arrays items backwards in javahow to reverse the elements in an array javahow ro reverse an array in javahow to reverse an array javajava code to reverse a arrayto reverse array in javareverse an array java libraryreversing an arraybackwards iteration javaoutputting array in reverse orderreverse an array in java using for loop