上面都寫的是一維數組了啊,如今對二維數組作一些操做。數組
1、思路app
首先,咱們要先將二維數組進行輸入,而後能夠將二維數組當作是一維數組,而後將他們進行組合,肯定終點起點與上下界,這樣皆能夠將其求出了。ui
2、代碼實現spa
首先從文件中讀取3d
1 File f1 = new File("input.txt"); 2 FileReader fr = new FileReader(f1); 3 BufferedReader br = new BufferedReader(fr); 4 StringBuilder sb1 = new StringBuilder(); 5 String hasRead; 6 while ((hasRead = br.readLine()) != null) { 7 sb1.append(hasRead + " "); 8 } 9 String text = sb1.toString(); 10 String[] textArray = text.split(" ");
而後將讀取到的數據進行存入到數組,對二維數組進行排序與看做是一位數組進行組合。code
1 for (i = 0; i < 5; i++) { 2 while (m + i < 5) { 3 for (cow = 0; cow < 5; cow++) { 4 sum[cow] = sum[cow] + a[m + i][cow]; 5 } 6 max = 0; 7 for (cow = 0; cow < 5; cow++) { 8 if (max + sum[cow] > sum[cow]) { 9 max = max + sum[cow]; 10 } else { 11 max = sum[cow]; 12 } 13 if (max > maxValue) { 14 maxValue = max; 15 } 16 } 17 m++; 18 } 19 m = 0; 20 for (cow = 0; cow < 5; cow++) { 21 sum[cow] = 0; 22 } 23 }
3、實驗截圖
input.txtblog
結果排序