Tuesday, 15 March 2011

java - Type mismatch when sorting 2D array -



java - Type mismatch when sorting 2D array -

this method supposed take 2 rows 3 columns array m, sort , output sorted array

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]; (int = 0; <= 2; i++) { sorted[i] = arrays.sort( m[i] ); //error- cannot convert void int } homecoming sorted; } }

i can't imagine void come from. mean?

it because arrays.sort() void method , doesn't have homecoming value

when in doubt, check documentation

java arrays sorting type-conversion

No comments:

Post a Comment