Non l'avevo visto subito (oltretutto, non uso Java 7 e lo switch su stringhe):
codice:
private static boolean prioritario(String opc, String op){
switch(opc){
case "^": if(op!="^") return true;
case "*": if(op=="+"||op=="-") return true;
case "/": if(op=="+"||op=="-") return true;
case "+": return false;
case "-": return false;
}
return false;
}
Le stringhe (ed in generale gli oggetti) non si confrontano con gli operatore relazionali, ma si deve usare il metodo equals().
codice:
String str1 = ...;
String str2 = ...;
if (str1 == str2) { // SBAGLIATO (quasi sempre false)
...
}
if ( str1.equals(str2) ) { // CORRETTO
...
}
if (str1 != str2) { // SBAGLIATO (quasi sempre true)
...
}
if ( !str1.equals(str2) ) { // CORRETTO
...
}
Ciao.