Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/08/2008, 16:13
LILYSMR
 
Fecha de Ingreso: agosto-2008
Mensajes: 11
Antigüedad: 15 años, 7 meses
Puntos: 0
Exclamación Problema con división

TENGO UN PROBLEMA.. BUENO HICE UN EJERCICIO PARA EJECUTAR UNA DIVISIÓN PERO SIN USAR EL OPERADOR / Y EL MOD... ENTONCES LO HICE CON UNA RESTA... PERO MI PROBLEMA ES QUE CUANDO LO EJECUTO ... EL RESIDUO CUANDO DEBE DE SER CERO... ME APARECE 1 Y NO SE COMO ELIMINAR ESE 1.. AQUI LES DEJO EL CODIGO... LO HICE CON UNA CLASE:
CODIGO DE LA CLASE
public class dividiendo {
private int A;
private int B;
public int resultado;
public int residuo=0;

public dividiendo(int divisor, int dividendo) {
this.A=divisor;
this.B=dividendo;
this.resultado=B;
}

public void calcular(int X, int Y) {

do
{
resultado=resultado-A;
residuo++;
}while(resultado>A);


}

}


CODIGO DE BOTÓN DIVIDIR
void jBtnCalcular_actionPerformed(ActionEvent e) {
int A= Integer.parseInt(jTxtDiv.getText());
int B=Integer.parseInt(jTxtDivi.getText());

dividiendo div = new dividiendo(A,B);
div.calcular(A,B);
Integer Resul = new Integer (div.resultado);
jTxtDivision.setText(Resul.toString());
Integer Residuo = new Integer (div.residuo);
jTxtResiduo.setText(Residuo.toString());

}

void jBtnSalir_actionPerformed(ActionEvent e) {
System.exit(1);
}
}