美文网首页
Java数组 反转

Java数组 反转

作者: 黑咔 | 来源:发表于2020-04-13 18:50 被阅读0次

    数组的反转

    方式一:

            String[] reverse = new String[]{"AA", "BB", "CC", "DD", "EE", "FF", "GG"};
    
            for (int i = 0; i <= (reverse.length - 1) / 2; i++) {
                String tmp = reverse[i];
                reverse[i] = reverse[reverse.length - i - 1];
                reverse[reverse.length - i - 1] = tmp;
            }
    

    方式二:

            String[] reverse = new String[]{"AA", "BB", "CC", "DD", "EE", "FF", "GG"};
    
            for (int i = 0, j = reverse.length - 1; i < j; i++, j--) {
                String tmp = reverse[i];
                reverse[i] = reverse[j];
                reverse[j] = tmp;
            }
    

    相关文章

      网友评论

          本文标题:Java数组 反转

          本文链接:https://www.haomeiwen.com/subject/slraectx.html