java intercambiar la posicion de valores de un array

Solutions on MaxInterview for java intercambiar la posicion de valores de un array by the best coders in the world

showing results for - "java intercambiar la posicion de valores de un array"
David
15 Jun 2016
1int lastElement = values[values.length-1];
2values[values.length-1] = values[0];
3values[0] = lastElement;
4
Agathe
13 Oct 2019
1public class ArrayMethods {
2
3private int[] values;
4public ArrayMethods(int[] initialValues) {
5values = initialValues;
6}
7public void swapFirstAndLast() {
8int lastvalplace = values.length;
9int firstval = values[0];
10values[0] = values[lastvalplace];
11values[lastvalplace] = firstval;
12}
13
14public static void main(String[] args) {
15ArrayMethods initialValues = new ArrayMethods(int[] 50, 32, 4, 9, 2);
16swapFirstAndLast = new swapFirstAndLast(values);
17}
18
19}
20
similar questions