自然數轉換爲二維矩陣可用於笛卡爾乘積型數據進行內存分頁

 @Test
    public void testNaturalTraslateMatrix(){
        int row = 7;
        int column = 8;
        int total = row * column;
        String[] rowStrList = new String[row];
        for (int k = 0; k < row; k++) {
            rowStrList[k] = "row" + k;
        }

        String[] columnStrList = new String[column];
        for (int k = 0; k < column; k++) {
            columnStrList[k] = "column" + k;
        }

        for (int k = 1; k <= total; k++) {
            int i = k / column;
            int j = k % column - 1;
            String currentRowStr = (j == -1) ? rowStrList[i-1] : rowStrList[i];
            String currentColumnStr = (j == -1) ? columnStrList[column - 1] : columnStrList[j];
            System.out.println("自然數: " + k + ", 行位置:" + currentRowStr + "列位置:" + currentColumnStr);
        }


    }
想想有什麼應用場景???
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章