diff --git a/src/main/java/HelloEnumsApp.java b/src/main/java/HelloEnumsApp.java index a098fec..de26166 100644 --- a/src/main/java/HelloEnumsApp.java +++ b/src/main/java/HelloEnumsApp.java @@ -1,6 +1,6 @@ public class HelloEnumsApp { public static void main(String[] args) { - Ordenacion ordenacion = obtenerOrdenCadena1("Albania", "Alba"); + Ordenacion ordenacion = obtenerOrdenCadena1("Alba", "Albania"); System.out.println(ordenacion); } @@ -26,14 +26,25 @@ private static boolean isGreaterString1ThanString2(String cad1, String cad2) { int posCurrentChar = 0; - int numMaxChars = Math.min(numCarsCad1, numCarsCad2); + int numTotChars = Math.min(numCarsCad1, numCarsCad2); - while(posCurrentChar < numMaxChars && isGreater) { + boolean foundDif = false; + + while(posCurrentChar < numTotChars && isGreater && !foundDif) { char currentChar1 = carsCad1[posCurrentChar]; char currentChar2 = carsCad2[posCurrentChar]; - isGreater = currentChar1 > currentChar2; + + if (currentChar1 != currentChar2){ + isGreater = currentChar1>currentChar2; + foundDif = true; + } posCurrentChar++; + } + if (posCurrentChar == numTotChars && !foundDif){ + isGreater = numCarsCad1 > numCarsCad2; + } + return isGreater; }