class Latex {
//enleve les espaces superflus dans une phrase passée en tableau
public static void espace(char[] tab) {
//enleve espaces superflus dans le tab
//variables
final char BLANC = ' ';
for (int i=0; i<= tab.length-2; i++) {
if (tab[i] == BLANC && tab[i+1] == BLANC) {
for (int j = i+1; j <= tab.length-2; j++)
tab[j] = tab[j+1];
tab[tab.length-1] = BLANC;
}
}
for (int k=0; k<=tab.length-1; k++)
System.out.print(tab[k]);
}
public static void main(String[] args) {
//variable tab
char[] tab = new char[5];
//initialisation tab
tab[0]='G';
tab[1]=' ';
tab[2]=' ';
tab[3]=' ';
tab[4]='M';
//appel de espace()
espace(tab);
}
}
Partager