A veces se acumulan varias condiciones anidando unas tras otras. Aunque correcto, el código puede llegar a ser ininteligible.
condiciones anidadas |
guardas |
public
String texto(double nota) { String txt; if (nota > 9.99) txt = "Matrícula de Honor"; else if (nota > 8.99) txt = "Sobresaliente"; else if (nota > 6.99) txt = "Notable"; else if (nota > 4.99) txt = "Aprobado"; else txt = "Suspenso"; return txt; } |
public
String texto(double nota) { if (nota > 9.99) return "Matrícula de Honor"; if (nota > 8.99) return "Sobresaliente"; if (nota > 6.99) return "Notable"; if (nota > 4.99) return "Aprobado"; return "Suspenso"; } |
Temas relacionados