簡體   English   中英

對2D數組排序時類型不匹配

[英]Type mismatch when sorting 2D array

該方法應該采用2行乘3列的數組m ,對其進行排序並輸出排序后的數組

import java.util.Arrays;
public class Foo {  
   public static void main(String[] args) {
     int[][] m1 = { { 14, 11, 13, 12 },
                    { 18, 15, 13, 13 },
                    { 19, 16, 15, 17 } };
     sortRows(m1);
   }
   public static int[][] sortRows(int[][] m) {
     int sorted[][] = new int[2][3];
     for (int i = 0; i <= 2; i++) {
        sorted[i] = Arrays.sort( m[i] ); //ERROR- cannot convert from void to int
     }
   return sorted;
   }
}

我無法想象虛空將從何而來。 那有什么意思?

這是因為Arrays.sort()是一個void方法,並且沒有返回值

如有疑問,請查閱文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM