martes, 3 de junio de 2008

Divisores de un número en java en modo gráfico

// Divisores de un número

import javax.swing.JOptionPane;
public class divisores2{


public static void main(String[] args) {
String numero;
int x, y=0, res;
numero= JOptionPane.showInputDialog("Escribe un numero");
x=Integer.parseInt(numero);
for(y=1; y<=x; y++){
res=x/y;
if(res%y==0 || x%y==0){
JOptionPane.showMessageDialog(null,"Los divisores son"+ res,"divisores",JOptionPane.QUESTION_MESSAGE);}
else
JOptionPane.showMessageDialog(null,"No hay mas divisores"+ x,"divisores",JOptionPane.WARNING_MESSAGE);
}
System.exit(0);

}
}

No hay comentarios: