Created
April 12, 2017 23:22
-
-
Save artlovan/b8a6b1ceb43e2bed582a4880aaafca34 to your computer and use it in GitHub Desktop.
Reverse values in an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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