class Temp
{
    static void sort1(int x[][])           //sort 2d  array
    {
        int temp = 0;
        for(int i=0;i<x.length;i++)
        {
            for(int j=i;j<x[i].length;j++)
            {
                for(int k=i;k<x.length;k++)
                {
                    for(int l=j;l<x[k].length;l++)
                    {
                        if(x[i][j] > x[k][l])
                        {
                            temp = x[i][j];
                            x[i][j] = x[k][l];
                            x[k][l] = temp;
                        }                        
                    }
                }
            }
        }
        System.out.println(".....Sorted Array.....");
        for(int i=0;i<x.length;i++)
        {
            for(int j=i;j<x[i].length;j++)
            {
                System.out.print(x[i][j] + "  ");
            }
        }
    }
    public static void main(String... s)
    {
        sort1(new int[][] { 
            {12, 7, 65}, 
            {87, 1, 4, 5, 31}, 
            {9, 76} 
            });
    }
}
When I'm running this program it is giving the output as
1  4  5  7  12  31  65. 
I expected it to be
1  4  5  7  9  12  31  65  76  87.
What is wrong with my code? It's missing results that it should be showing. Any help or insight would be greatly appreciated.
 
    