Click here to Skip to main content
15,867,453 members
Home / Discussions / Java
   

Java

 
GeneralRe: Help with a website written in Java Pin
Tim Kohl27-Nov-19 21:21
Tim Kohl27-Nov-19 21:21 
GeneralRe: Help with a website written in Java Pin
Gerry Schmitz28-Nov-19 5:37
mveGerry Schmitz28-Nov-19 5:37 
QuestionHelp With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 6:15
eskomo8424-Nov-19 6:15 
AnswerRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan24-Nov-19 6:23
mveRichard MacCutchan24-Nov-19 6:23 
GeneralRe: Help With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 6:45
eskomo8424-Nov-19 6:45 
GeneralRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan24-Nov-19 6:52
mveRichard MacCutchan24-Nov-19 6:52 
GeneralRe: Help With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 9:09
eskomo8424-Nov-19 9:09 
GeneralRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan24-Nov-19 23:14
mveRichard MacCutchan24-Nov-19 23:14 
My apologies also, i misunderstood the question. The issue is that you need to compare the surnames of each entry, and swap the two entries if the first one is greater than the second. This means swapping all three items in the array entry. The following code should do it.
Java
void sortContact(String[][] contactsArray, int numContacts) {
    String[] temp = new String[3];
    boolean changes;
    do {
        // we need to repeat this until no changes are made
        changes = false;
        
        // make sure we iterate through all contacts
        for(int i = 0; i < numContacts; i++) {

            // iterate through all the rest
            for(int j = i + 1; j < numContacts; j++) {

                // compare the two surnames
                if(contactsArray[i][1].compareTo(contactsArray[j][1]) > 0) {

                    // if the first surname is greater than the second, then swap them over
                    temp[0] = contactsArray[i][0];
                    temp[1] = contactsArray[i][1];
                    temp[2] = contactsArray[i][2];
                    contactsArray[i][0] = contactsArray[j][0];
                    contactsArray[i][1] = contactsArray[j][1];
                    contactsArray[i][2] = contactsArray[j][2];
                    contactsArray[j][0] = temp[0];
                    contactsArray[j][1] = temp[1];
                    contactsArray[j][2] = temp[2];

                    // keep going until there are no changes made
                    changes = true;
                }
            }
        }
    } while (changes == true);
}

QuestionJavaFX Background not beeing used on a ScrollPane element [Solved] Pin
Valentinor24-Nov-19 4:48
Valentinor24-Nov-19 4:48 
AnswerSolution Pin
Valentinor27-Nov-19 6:40
Valentinor27-Nov-19 6:40 
Question!!Please Help!! Student Needs Help It Shows me exercise/ wrong catagory moved to web dev JS Pin
Member 1465076510-Nov-19 6:04
Member 1465076510-Nov-19 6:04 
QuestionRe: !!Please Help!! Student Needs Help It Shows me exercise 2 is correct but exercise 1 is not defined Pin
Richard MacCutchan10-Nov-19 6:24
mveRichard MacCutchan10-Nov-19 6:24 
AnswerRe: !!Please Help!! Student Needs Help It Shows me exercise 2 is correct but exercise 1 is not defined Pin
Member 1465076510-Nov-19 11:15
Member 1465076510-Nov-19 11:15 
AnswerRe: !!Please Help!! Student Needs Help It Shows me exercise 2 is correct but exercise 1 is not defined Pin
Member 1465076510-Nov-19 12:03
Member 1465076510-Nov-19 12:03 
QuestionGlobal Histogram Implementation in Java Pin
Member 146130164-Oct-19 11:37
Member 146130164-Oct-19 11:37 
AnswerRe: Global Histogram Implementation in Java Pin
phil.o4-Oct-19 22:06
professionalphil.o4-Oct-19 22:06 
QuestionBiometric attendace machine data Pin
Member 146125164-Oct-19 1:15
Member 146125164-Oct-19 1:15 
AnswerRe: Biometric attendace machine data Pin
Richard MacCutchan4-Oct-19 3:19
mveRichard MacCutchan4-Oct-19 3:19 
AnswerRe: Biometric attendace machine data Pin
Gerry Schmitz4-Oct-19 6:35
mveGerry Schmitz4-Oct-19 6:35 
QuestionNeed to develop a program on Java for desktop Pin
Ryder Weber1-Oct-19 3:32
Ryder Weber1-Oct-19 3:32 
AnswerRe: Need to develop a program on Java for desktop Pin
Richard MacCutchan1-Oct-19 4:13
mveRichard MacCutchan1-Oct-19 4:13 
AnswerRe: Need to develop a program on Java for desktop Pin
Gerry Schmitz4-Oct-19 20:35
mveGerry Schmitz4-Oct-19 20:35 
Questionhow to reuse open browser in java selenium? Pin
nadavrock29-Sep-19 19:23
nadavrock29-Sep-19 19:23 
AnswerRe: how to reuse open browser in java selenium? Pin
Leanbridge Technologies1-Nov-19 23:07
professionalLeanbridge Technologies1-Nov-19 23:07 
QuestionJava Cant pass the value that user input as the string and view it Pin
raigen27-Sep-19 5:44
raigen27-Sep-19 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.