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
| //declaration de variables
int nombre;
double modulo;
String resultat="";
//Section d'entrée
String valeur = JOptionPane.showInputDialog(null,"Veuillez saisir un nombre");
nombre= Integer.parseInt(valeur);
if (nombre <0)
{
String valeur2= JOptionPane.showInputDialog(null,"Veuillez saisir un nombre positif");
nombre= Integer.parseInt(valeur2);
}
//Section de traitement
for(int index=0;index>0;index--)
{
for(int index1=0;index1>0;index1++)
{
modulo=nombre%2;
resultat = String.valueOf(modulo);
}
nombre/=2;
}
JOptionPane.showMessageDialog(null, "le nombre binaire est"+resultat) ;
}
} |
Partager