Java 循环不会切换数组中的所有值

Java 循环不会切换数组中的所有值,java,arrays,loops,Java,Arrays,Loops,目前,我正在尝试循环一个数组,以便根据其他特定值切换值。我知道可能有更好的方法来排序或重新排列数组,但我想用这种方法来学习它 这是我的多维数组 public static String[][] people = new String[][] { { "John", "blah", "120", "4" }, { "Amy ", "blah", "99", "4" }, { "Sophie", "bl

目前,我正在尝试循环一个数组,以便根据其他特定值切换值。我知道可能有更好的方法来排序或重新排列数组,但我想用这种方法来学习它

这是我的多维数组

 public static String[][] people = new String[][]
    {
    {
        "John", "blah", "120", "4"
    },
    {
        "Amy ", "blah", "99", "4"
    },
    {
        "Sophie", "blah", "100", "4"
    },
    {
        "Sarah", "blah", "98", "4"
    },
    {
        "Claire", "blah", "101", "4"
    },
    {
        "Rob", "blah", "105", "3"
    },
    {
        "Steve ", "blah", "85", "3"
    },
    {
        "Della", "blah", "102", "3"
    },
    {
        "Ron", "blah", "95", "3"
    },
    {
        "Bob", "blah", "102", "3"
    },
    };
这就是应该重新排列这些记录并将它们放入字符串中以显示在对话框中的方法

public static void main(String[] args)
    {
        String table = "";
        table = "<html><table'>";
        int ranking = 0;
        int m = 1;
        for (int i = 0; i < people.length; i++)
        {

            if (i + 1 < people.length && people[i][3].equals(people[i + 1][3]))
            {
                if ((Double.parseDouble(people[i][2])) > (Double.parseDouble(people[i + 1][2])))
                {
                    String first1 = people[i][0];
                    String first2 = people[i][1];
                    String first3 = people[i][2];
                    String first4 = people[i][3];
                    String second1 = people[i + 1][0];
                    String second2 = people[i + 1][1];
                    String second3 = people[i + 1][2];
                    String second4 = people[i + 1][3];
                    System.out.println(first3);
                    System.out.println(second3);
                    System.out.println("time to switch lol");
                    people[i][0] = second1;
                    people[i][1] = second2;
                    people[i][2] = second3;
                    people[i][3] = second4;
                    people[i + 1][0] = first1;
                    people[i + 1][1] = first2;
                    people[i + 1][2] = first3;
                    people[i + 1][3] = first4;
                    // array[i][2] = temp2;
                    // array[m][2] = temp1;
                    System.out.println(i);
                    System.out.println(i + 1);
                  //  break;
                }
                m++;

            }
        }
        for (int i = 0; i < people.length; i++)
        {
            table += "<tr><td style=colspan='5'><center>" + ranking + "</center></td>";
            table += "<td style=colspan='5'><center>" + people[i][0] + "</center></td>";
            table += "<td style=colspan='5'><center>" + people[i][2] + "</center></td>";
            table += "<td style=colspan='5'><center>" + people[i][3] + "</center></td><tr>";
            ranking++;
        }
        JOptionPane.showMessageDialog(null, table); //shows results in joptions pane
    }
}
publicstaticvoidmain(字符串[]args)
{
字符串表=”;

表="通过调试器,你从中了解到了什么?我运行了你的代码,结果是艾米、索菲、莎拉、克莱尔、约翰、史蒂夫、德拉、罗恩、鲍勃、罗布,根据你的数据和代码,顺序看起来是正确的。你期望的顺序是什么?顺序应该是莎拉、艾米、索菲、克莱尔、约翰、史蒂夫、罗恩、鲍勃、德拉、罗布。我设法做到了最后,使用一个布尔值和一个while语句继续循环和交换记录,只要该值是真的,它就可以现场工作