Structure if dans java

Résolu/Fermé
yanounou - 13 sept. 2008 à 09:37
 williamdes - 21 févr. 2014 à 23:13
Bonjour,
voila je voudrais realiser un petit programme tou simple en java avec un if, le voila

public static void main (String[] args) {

String p1 = "fruit";
String p2 = "legumes";

if (p1 = p2)
System.out.println("Ces mots sont egaux");

else
System.out.println("Ces mots sont differents");

}


}
Mais au moment ou j'execute le programme ca me met : Type mismatch: cannot convert from String to boolean
d'ou le probleme pourrait venir???
A voir également:

2 réponses

vignemail1 Messages postés 1246 Date d'inscription vendredi 8 octobre 2004 Statut Contributeur Dernière intervention 13 septembre 2019 259
13 sept. 2008 à 10:46
if (p1 == p2)

ou alors

if (p1.equals(p2))

ou alors

if (p1.equalsIgnoreCase(p2))

ou alors

if (p1.compareTo(p2) == 0)
2
merci infiniment pour if (p1.equals(p2))
c génial
0
merci beaucoup, maintenant ca marche.
1