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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
public class TrierMots
{
/**
* @param args
*/
public static void main(String[] args)
{
String listeMots[] = new String[6];
String plusPetitMot = "";
String croissant[] = new String[6];
String sortie = "";
int i = 0;
int j = 0;
int k = 4;
boolean trier = false;
for (i=0;i<5;i++)
{
listeMots[i] = JOptionPane.showInputDialog(null,"Entrer un mot svp");
croissant[i] = listeMots[i];
}
i=0;
plusPetitMot = listeMots[0];
while(trier == false)
{
for (j=0;j<k;j++)
{
if(plusPetitMot.compareTo(listeMots[j+1]) > 0)
plusPetitMot = listeMots[j+1];
}
croissant[i] = plusPetitMot;
plusPetitMot = listeMots[i+1];
sortie = sortie + croissant[i] + "\n";
i++;
k--;
if(croissant[0].compareTo(croissant[1]) <=0 && croissant[1].compareTo(croissant[2]) <=0 && croissant[2].compareTo(croissant[3]) <=0 && croissant[3].compareTo(croissant[4]) <=0)
trier = true;
}
JOptionPane.showMessageDialog(null,sortie);
}
} |
Partager