CÓDIGO:
/**
*
* @author FRANCISCO
*/
public class Intercambio {
private int n1;
private int n2;
public Intercambio() {
// TODO Auto-generated constructor stub
n1=0;
n2=0;
}
public void EstablecerValores (int x, int y){
n1=x;
n2=y;
}
public void intercambiar (){
int aux;
aux=n1;
n1=n2;
n2=aux;
}
public int ObtieneValor1 (){
return n1;
}
public int ObtieneValor2(){
return n2;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int a = 6; int b = 8;
Intercambio ob = new Intercambio ();
ob.EstablecerValores(10, 40);
System.out.println ("los valores ingresados son:"+ ob.ObtieneValor1()+ "--"+ ob.ObtieneValor2());
ob.intercambiar();
System.out.println ("los valores intercambiados son:"+ ob.ObtieneValor1()+ "-- "+ ob.ObtieneValor2());
}
}
0 Comments: