Bonsoir, j'ai créé un programme prenant en entrée une phrase et indique s'il y a des mots identiques ou pas,
si il fonctionnait bien, pour "Lol lel Lol", il devrait m'indiquer qu'il y a des mots identiques.
Voici mon programme :
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String phrase ;
System.out.println("Enter a sentence :");
phrase = sc.nextLine();
String[] T = phrase.split(" ");
int i=0, o=0 ; //iterators
boolean b=false; //redundancy condition
for(String s : T)
{
System.out.println("T["+i+"] = "+ s);
while(b)
{
if(o!=i)
{
if(s==T[o])
{
b=true;
}
}
o++;
}
i+=1;
}
if(b)
{
System.out.println("There are identical words.");
}
else
{
System.out.println("There are no identical words.");
}
}
Message édité le 27 janvier 2016 à 18:07:06 par VIeRepublique