reverse an array in java using while loop

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

showing results for - "reverse an array in java using while loop"
Lia
06 Jul 2019
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)); 
Frieda
14 Feb 2019
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}
queries leading to this page
reverse array javafunction java reverse two dimensional arrayreverse an array in java using keywordarray reverse in java utility functionjava reverse an arrayreverse an array in java using inbuilt functionreverse an integer array in javaprint reverse number in array javareverse arry in place javajava util arrays reversereverse array string in javareverse arraay in javaarray in reverce in javahow ro reverse an array in javajava reverse method arrayreverse a array javafastest way to reverse elements in array javareverse function for arrays in javareverse order of array in javareverse arr javajava reverse array public methodflip int arrayreverse array in javareverse a sub array in javahow to reverse an integer from the array in javahow to reverse a array in javaprogram to reverse array in javajava code to reverse an arrayfor loop to reverse array javajava program to reverse an array ireverse java arraujava arrays reversearray element in reverse javaturning an array into two strings and reverse ithow to reverse an array in java builtinjava reverse sort arrayjava reverse array elementsreverse array in java functionhow to reverse a arry in javahow to reverse an int array in javareverse method in array in javareverse array in place in javareverse array in java inbuiltprint array elements in reverse order in javaarrays reverse jvareverse array in java using methodreverse integer array in javaprint reverse of an array javaarray reverse utility in javajava reversearrayhow do you reverse an array in place in javajava reverse an int arrayreverse order of array javareversing int 5b 5d array in javareverse function in java to reverse arrayreverse an integer array javareverse in java arrayshow to print array in reverse javaflipping array javajava sort array reversearrays reverse 28 29 in javahow do you reverse an array in place in java 3freverse array javareverse array using java 27how to reverse an array javahow to reverse complete array javareverse aray in javareverse array java 3dreverse array in parts javareverse method array javareverse the array javajava reverse int arrayarrays reversejava reverse string arraymethod to reverse a array in javareverse order an array javahow to reverse order an array in javahow to reverse the order in an array in javaprinting to an array in reverse in java with while loopreverse elements in array javahow to reverse an array in java inbuiltreverse array of javahow to reverse a arrray in javarevese a array in javajava arrays reversereverse array integer in java using for loopreverse an array in place javarevers order array javareversearray javareverse in javainvert an array javareversing a array in javais there inbilt function to reverse the array in javahow to reverse complete array java inbuitrevers array in javajava program to reverse an array reversing array in javahow to reverse the elements in an array javacreate a bew array reversedreverse order of integer array in javahow to reverse a array in jaavareverse in java arrayreverse array elements javareverse sort java arrayreverse array in javaprint elements of array in reverse javareverse array java gfgjava return reverse arrayreverse arraysliar javaflip int 5b 5d 5b 5d arrayreverse sort array in javajava array reverse sortjava array reversereverse an array using function in javahow to put an array in reverse orderfilp integer arrayreverse java arrayarray reverse sort in java reverse 28 29 in javahow to reverse array elements in javahow to reverse a n array in javaprint reverse array feom user in javahow to reverse a array javareverse in array javainvert java arraydeclare 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 arrays reverse javamethod to reverse n array in javareverse array order javareverse array method in javaproblem to reverse an array in javahow to reverse integer array in javahow to reverse the items in an arrayhow to reverse order of an array in javajava array rverse functionreturn reverse array javareverse the array in java methodreverse sort array javahow to read an array in reverse orderreverse inplace array in java java program to reverse value of array elementsreverse array sort javaarray java reversehow to print the reverse of an array in javajava sort a array reversehow to reverse array in java programreverse a integer array in javareverse an arr javareverse array indexing javahow to reverse a integer array in javajava loop array backwardshow to print array in reverse order in javamethod in java to reverse arrayreverse array method javareverse array algorithm javahwo to reverse array in javahow to return an array in reverse order javareversing an array in javareverse numbers in an array javaefficient way to reverse an array in javajava invert arrayfunction to reverse array in javareverse array function javajava reverse arrazreverse the given array in javajava inverting arrayprogram to reverse an array in javaprint elements of array in reverse order javareverse array elements in java using reverse functionreverse elements in an array javareverse arr in javareversing elements in an array javahow to take values in array and return in opposite order javahow to reverse data in array in javahow reverse array javahow to sort array reverse in java 3f reverse in javamethod reverse the array in javajava reverse array functionhow to reverse the elements in an arrayarray reverse 28 29 javajava program to get an array from user and reversereversearray method that accepts an array as parameter 2c reverse an array and return the reversed array sort array backwards javajava reverse methodprogramme to reverse an array in javahow to return a reverse array in javaarrays reverse in javahow to reverse int 5b 5d array in javainbuilt method to reverse a array in javahow to reverse loop through the array in javaarray operations in java reversereverse an array in java methodhow to reverse an array method in javaarray reverse javareverse ana array javaprint reverse array from user in javareverse the digit of array and concatenate javaarray reverse order javahow to return reverse order javahow to reverse elements in an array javaarray reverse in java inbuilt functionreverse a array in javainverting a java arrayhow to reverse the order of an int array in javaefficient java code to reverse array elementscode segments that reads 10 and display in reverse order in array javahow to print a reverse array in javajava inbuilt function to reverse the arrayarray reverse function injavaarrays sort in java reversehow to reverse number in array in javahow to print an array in reverse order javahow to do reverse array in javajava to take array from user and reverse in javareverse array in havato reverse elements of an array in javareverse array program in jvaahow to reverse the order of an array javarevere an array in javajava loop in reversejava code to reverse int arrayreverse an array in java using while loophow to print array in reverse order java java reverse arraydequereverse int array javareverse array in jvahow to reverse array data in javareverse array in java libraryfunction reversearray 28collection 29reverse array element in javaint array reverse javajava code to return reverse an arrayarray reverse javareverse the array in javareverse aray javareverse array and return array in javahow to reverse array javareverse of an array in javahow to reverse the array elements in javaarrays reverse function in javareverse array elements in javajava reverse arrayrevert array javaarrays reverse order javareverse an array in java programarrays rev in javareverse array jaavaprogrammiz reverse array in javareverse loop in javahow to reverse an array in java inbuilt functionarray reverse method in javaarray reverse java codereversing array javaprogramme to print an array in reverse order in javareverse array using only one variable in javajava revser arrayjava reverse array integershow to reverse the order of an arrayjava program to print reverse of an arrayhow to reverse in javareversing arrays in javajava how to reverse an arraycreate java function to reverse arrayreverse of array in javahow to reverse the contents in an array javareverse java function arrayrevrsing an array in javareverse array int in javareverse integers of arrayreverse an array java libraryrevers array javareverse array in java 8java reverse array loophow to reverse an array java 5carray reverse java methodreverser array javareverse order array javareverse an array in ajavareverse values of an array in javarevert an array javareverse an array in javajava code to reverse a arrayprinting an array in reverse order javaprogram in java to read n number of values in an array and display in reverse order using arraylistwrite a java program to reverse a given array using methodreverse arrray javahwo to reverse content of an array in androidinverti array javaarrays reverse in javaflip array javareverse array java codewrite a java program to reverse an array of integer values return array in reverse order javahow to reverse an arrayreverse integer in pythonhow to reverse array in java in builtexample of reversing array in javajava array reversestatic int 5b 5d reverse array 28int 5b 5d a 29 c 23how to invert an arraybest way to reverse array in javareverse an array in javahow to solve a reverse array in javahow to access arrays items backwards in javahow to reverse an array in ajavareverse java int arrayhow to reverse the array in javamethod to reverse an array in javabackwards arrays javareverse and array in javajava arrays reverse sortjava reverse order of elments in arrayhow to flip an array in javahow to invert an array in javarevers array integer in javahow to reverse elements in an arrayreverse a n array javareverse an array in java using for loophow to reverse array in jvaavalues of array in reverse orde in javahow to reverse order an arrayhow to invert an array javareverse array in java using for loopreversing arrsy javaflip an array javahow to output an array backwards with doubles javadisplay the array elements in reverse order javahow to write a reverse array method jvareverse 28 29 in javaarray reverse in javarevese an array in javaprint reverse array javahow to make array reverse method in javainteger array reverse in javawrite a program to reverse an array in javajava how to reverse aarrayhow to return an array in reverse in javahow to reverse a array in javareverse an array in java functionto reverse a array in javareverse an int array javahow to reverse an array without using another array in javahow to reverse an array in java using inbuilt functionarrays reverse javajava array reverse orderarray string reverse in javajava reverse array without built in functionarr reverse javaprint an array backwards in javareversing operation in array in javaarray reverse java 8java revers arrayrevering an arrayreverse array function in javareverse an int array in javareverse number in array javarev array javajava function to reverse an arrayloop array in reverse javareverse array havareverse une array javareverse the array in jaavreverse array number in javaallintitle 3areverse an array in java using for loopreverse an arrayprint reverse array in javasimilarly 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 invert a array javahow to do a reversed arrayhow to reverse an array in javareverae array in hjavareverse inbuilt function for array in javareverse arrray in java reverse order of an array in javareverse a 1d array in javareversing an array javajava array command to reverse a numberhow to reverse an array of integers in javajava util arrays reverseinvert array java java reverse arrrayhow to print an array in java reversehow to reverse array in javajava reverse array orderhow to print reverse array in javareversing an arrayhow to reverse an array in java without using reverse functionreverse array java for loopreverse array shortcut javareverse arra javacode for reversing an array in javareversing an arrar in javacreate reverse array javareverse arrya in javawrite a java program to reverse an array recursive reverse string javaarray reverse in javareverse an array with begin and end in javareverse sort an array javareverse a string array javahow to reverse an integer array in javabuilt in function to reverse array in javahoe to reverse the array in javahow to put reversed array in new array javaprint array in reverse order in javaarray reverse javatake array from user and reverse in javaarray reverse function in javareverse array java code easy codeuser reversal algorithm in javaarrays reverse sort in javaeverse an array javaarray loop to display the reverse of all number in the array javahow to take array reverse in javahow to turn a set of strings into an array and then reverse that arrayreverse all elements of array javareverse the array elements in javalogic to reverse an array in javareverse an array from start and end in javareverse values in array javadisplay array values in reverse order in javahow to print array elements in reverse order javajava inbuilt methods to revese an arrayreversing an array n 5e2java reverse array methodreverse elements of array in javaarrays sort reverse in javareverse array sort in javajava method reverse arrayarrays reverse javareverse a arrayin ajvareverse 10 element array reverse javato reverse array in javamethod to reverse array in java 2f 2f reverse an array in java using for loopreverse method in javaprogram or reversing array in javabest way to reverse array javasorted map in javareverse an array javareverse array java libraryreverse a number in java in arrayclass container reversing arrayreverse an array of integersjava reverse arrayswrite the reverse method array javaarray reverse in java methodreverse of integer array in java using java 8 collectionsreverse java array intarray reverse java libraryrverse array in havareverse an array java 5dreverse method arrays javahow to display the elements of an array in reverse javahow do we reverse an array in javareverse arry javareverse a list in javahow to reverse an array in java in placehowto reverse array withoutcollectionsreverse an array in java using while loop