-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cambios.java
48 lines (39 loc) · 1.07 KB
/
Cambios.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.Arrays;
/**
* Clase para probar el paso de parametros por valor
* @author Mauricio Chávez Olea
* @version 17102017
*/
public class Cambios{
public String toString(int [] arr){
return Arrays.toString(arr) ;
}
public void intercambiar1(int x, int y){
int temp;
temp = x ;
x = y ;
y = temp ;
}
public void intercambiar2(int [] a, int [] b){
int temp = a[0] ;
a[0] = b[0] ;
b[0] = temp ;
}
public static void main(String[] args) {
Cambios test = new Cambios();
int x = 10;
int y = 30;
int [] a = {-13,20,60};
int [] b = {10, 39, -1, 8};
System.out.println("***Valores originales***");
System.out.println("x = " + x + ", y = " + y);
System.out.println("Arreglo a: " + test.toString(a));
System.out.println("Arreglo b: " + test.toString(b));
test.intercambiar1(x,y);
test.intercambiar2(a,b);
System.out.println("***Valores despues de aplicar el cambio***");
System.out.println("x = " + x + ", y = " + y);
System.out.println("Arreglo a: " + test.toString(a));
System.out.println("Arreglo b: " + test.toString(b));
}
}