public static void printMatrixInSpiral(int [][] input) {
        int leftTop = 0;
        int rightTop = input[0].length;
        int leftBottom = -1;
        int rightBottom = input.length;
        int i=0; int j=0; int count =0;
        while(count<input.length * input[0].length){
            while(true){
                if(j<rightTop){
                    System.out.println(" "+input[i][j++]+" ");
                    count++;
                } else {
                    rightTop--;
                    j--;
                    i++;
                    break;
                }
            }

            while(true) {
                if(i<rightBottom){
                    System.out.println(" "+input[i++][j]+" ");
                    count++;
                } else{
                    i--;
                    j--;
                    rightBottom--;
                    break;
                }
            }

            while(true) {
                if(j>leftBottom){
                    System.out.println(" "+input[i][j--]+" ");
                    count++;
                } else{
                    j++;
                    i--;
                    leftBottom++;
                    break;
                }
            }

            while(true) {
                if(i>leftTop){
                    System.out.println(" "+input[i--][j]+" ");
                    count++;
                } else{
                    i++;
                    j++;
                    leftTop++;
                    break;
                }
            }
        }

    }