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
|
package fr.orsay.td01;
import java.util.Scanner;
public class td1_exo1_2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez votre phrase SVP");
String phrase = sc.nextLine();
char [] tab = phrase.toCharArray();
char test = ' ';
String mot="";
String tab1[] = new String[phrase.length()];
int i = 0;
int j = 0;
while(i<phrase.length()) {
if(tab[i]!=test) {
mot = mot + tab[i];
}
if (tab[i]==test) {
tab1[j] = mot;
j++;
mot = "";
}
i++;
}
for(int k=0;k<j;k++) {
System.out.println(tab1[k]);
}
}
} |