Crear un programa que calcule el MCD de dos numeros enteros
Realizar el siguiente formulario en Netbeans
Cambiamos de nombre de la Variable(JTextField1) por txtnum1Cambiamos de nombre de la Variable(JTextField2) por txtnum2
Cambiamos de nombre de la Variable(jButton1) por btnnuevoCambiamos de nombre de la Variable(jButton2) por btnmostrarCambiamos de nombre de la Variable(jButton3) por btnsalir
Cambiamos de nombre de la Variable(jLabel4) por lblrpta
CODIGOS DE LOS BOTONES
CODIGO BOTON NUEVO
txtnum1.
setText("");
txtnum2.
setText("");
CODIGO BOTON MOSTRAR
int num1,num2,mcd=0,min;
num1 = Integer.parseInt(txtnum1.
getText().
trim());
num2 = Integer.parseInt(txtnum2.
getText().
trim());
if(num1
< num2
){
min
= num1;
}else{
min
= num2;
}
for(int i
=1;i
<=min;i
++){
if(num1
% i
== 0
&& num2
% i
== 0
){
mcd = i;
}
}
lblrpta.
setText(" El MCD de "
+num1
+ " y "
+num2+ " es: "
+mcd);
CÓDIGO BOTON SALIR
System.exit(0);
RESULTADO FINAL