Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Reverse array java

import java.util.Arrays; 

public class Main {
    public static void main(String[] args) {
        int[] numbers = {1, 2, 3, 4, 5};
        reverse(numbers);
        /*
            output is:
                Array = [1, 2, 3, 4, 5]
                Reversed array = [5, 4, 3, 2, 1]
        */
    }
    
    public static void reverse(int[] array) {
        System.out.println("Array = " + Arrays.toString(array));
        int maxIndex = array.length - 1;
        int halfLength = array.length / 2;
        for (int i = 0; i < halfLength; i++) {
            int temp = array[i];
            array[i] = array[maxIndex - i];
            array[maxIndex - i] = temp;
        }
        System.out.println("Reversed array = " + Arrays.toString(array));
    }
}
Comment

reverse array java

//With Commons.Lang, you could simply use

ArrayUtils.reverse(int[] array)

// For reversing subarray
ArrayUtils.reverse(int[] array,int startIndexInclusive, int endIndexExclusive)


Comment

reverse a integer in java

while(num != 0) 
{
   int digit = num % 10;
   reversed = reversed * 10 + digit;
   num /= 10;
}
Comment

reverse int array java

import java.util.*;
import java.util.stream.Collectors;

int[] array = new int[] {23, 54, 12};
List<Integer> list = Arrays.stream(array).boxed().collect(Collectors.toList());
Collections.reverse(list);
array = list.stream().mapToInt(x -> x).toArray();
//array = [12,54,23]
Comment

java reverse array

public void reverseArray(int[] arr) {
	int len = arr.length;
    int left = 0, right = len - 1 - left;
    while (left < right) {
        swap(arr, left, right);
        left++;
        right--;
    }
}
    
private void swap(int[] arr, int left, int right) {
    int tmp = =arr[left];
    arr[left] = arr[right];
    arr[right] = tmp;
}
Comment

array reverse in java

        int[] xr = {1, 2, 3, 4, 5};

        System.out.print("[");
        for (int i = xr.length - 1; i >= 0; i--) {
            System.out.print(xr[i] + ", ");
        }
        System.out.println("]");
    }
Comment

java reverse a array

// Algorithm
wide_floating_point e() {
  unsigned n = 33;
  my_uint128 num = 1;
  my_uint128 den = 1;
  for (unsigned i=1; i <= n; i++) {
    num = num*i + 1;
    den = den*i;
  }
  return (wide_floating_point) num/fact;
}
Comment

java reverse array

WWWWW-
S---W-
W-W-W-
W-W---
E-W-W-
WWWWW-
Comment

PREVIOUS NEXT
Code Example
Java :: jtable get get row 
Java :: set path in windows 
Java :: converter float para string em java 
Java :: guessing game in java 
Java :: how to move a marker on google maps in android studio 
Java :: how to remove null values collections 
Java :: java convert date to localdate 
Java :: how to find the length of a string in java without using length function 
Java :: sort a string array java 
Java :: set source image in android studio 
Java :: spring maven plugin 
Java :: how to get color from resource android 
Java :: wrapper classes in java 
Java :: javafx textarea size 
Java :: glide library in android studio 
Java :: how to output sum of even numbers in java between two user values 
Java :: java  
Java :: encapsulation in oop 
Java :: java print formatted string 
Java :: java convert float to double 
Java :: array arraylist java 
Java :: java basic syntax 
Java :: java make a null string 
Java :: comentario java 
Java :: how to get 2 decimal places in java 
Java :: java bufferedreader read all lines 
Java :: java print default options 
Java :: how to check number format exception in java 
Java :: uses or overrides a deprecated API. 
Java :: android studio get id name from view 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =