Arrays go brrrrrrrr

master
Chloe Fontenot 🏳️‍⚧️ 2023-01-11 10:35:10 +07:00
parent 5834c5aa99
commit 3c32d0a20b
1 changed files with 9 additions and 4 deletions

@ -186,11 +186,16 @@ public class Lab2DArrays_CalebFontenot {
for (int j = i + 1; j < ar1.length; ++j) { for (int j = i + 1; j < ar1.length; ++j) {
// Compare all chars in string if first chars match // Compare all chars in string if first chars match
char compChar1 = ar1[i].charAt(0), compChar2 = ar1[j].charAt(0); char compChar1 = ar1[i].charAt(0), compChar2 = ar1[j].charAt(0);
for (int index = 1; index < ar1[i].length(); ++index) {
if (Character.toLowerCase(compChar1) == Character.toLowerCase(compChar2)) { if (Character.toLowerCase(compChar1) == Character.toLowerCase(compChar2)) {
compChar1 = ar1[i].charAt(1); try {
compChar2 = ar1[j].charAt(1); compChar1 = ar1[i].charAt(index);
compChar2 = ar1[j].charAt(index);
// Note: I'm not happy with this implementation, but it works as long as you're only having to compare 1 other character. } catch (Exception ex) {
// If it's failed, the index has gone out of range.
break;
}
}
} }
if (Character.toLowerCase(compChar1) > Character.toLowerCase(compChar2)) { if (Character.toLowerCase(compChar1) > Character.toLowerCase(compChar2)) {
String temp = ar1[i]; String temp = ar1[i];