Arrays go brrrrrrrr
This commit is contained in:
parent
5834c5aa99
commit
3c32d0a20b
@ -186,11 +186,16 @@ public class Lab2DArrays_CalebFontenot {
|
||||
for (int j = i + 1; j < ar1.length; ++j) {
|
||||
// Compare all chars in string if first chars match
|
||||
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)) {
|
||||
compChar1 = ar1[i].charAt(1);
|
||||
compChar2 = ar1[j].charAt(1);
|
||||
|
||||
// Note: I'm not happy with this implementation, but it works as long as you're only having to compare 1 other character.
|
||||
try {
|
||||
compChar1 = ar1[i].charAt(index);
|
||||
compChar2 = ar1[j].charAt(index);
|
||||
} catch (Exception ex) {
|
||||
// If it's failed, the index has gone out of range.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Character.toLowerCase(compChar1) > Character.toLowerCase(compChar2)) {
|
||||
String temp = ar1[i];
|
||||
|
Loading…
Reference in New Issue
Block a user