Skip to content

Instantly share code, notes, and snippets.

@artlovan
Created April 12, 2017 23:22
Show Gist options
  • Save artlovan/b8a6b1ceb43e2bed582a4880aaafca34 to your computer and use it in GitHub Desktop.
Save artlovan/b8a6b1ceb43e2bed582a4880aaafca34 to your computer and use it in GitHub Desktop.
Reverse values in an array
import java.util.Arrays;
public class Reverse {
private static int[] data = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
public static void main(String[] args) {
reverse();
System.out.println(Arrays.toString(data));
}
public static void reverse() {
for (int i = 0; i <= data.length/2; i++) {
int temp = data[data.length - i - 1];
data[data.length - i - 1] = data[i];
data[i] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment