1. 程式人生 > 實用技巧 >每天一篇程式碼系列(4)

每天一篇程式碼系列(4)

 1 import java.util.*;
 2 class O3_2 {
 3   public static void main(String args[ ]) {
 4     Scanner buf=new Scanner(System.in);
 5     int[][] nums=new int[2][3];
 6     int i=0,j=0,max,row=0,col=0;
 7     System.out.print("輸入一個兩行三列的矩陣:");
 8     System.out.println();
 9     for(i=0;i<2;i++) {
10       for
(j=0;j<3;j++) { 11 nums[i][j]=buf.nextInt(); 12 } 13 } 14 for(i=0;i<2;i++) { 15 for(j=0;j<3;j++) { 16 System.out.print(nums[i][j]+" "); 17 } 18 System.out.println(); 19 } 20 max=nums[0][0]; 21 for(i=0;i<2;i++) { 22 for(j=0;j<3;j++) {
23 if(nums[i][j]>max) { 24 max=nums[i][j]; 25 row=i; 26 col=j; 27 } 28 } 29 } 30 System.out.println("最大的數為:"+max+",在第"+row+",行第"+col+"列"); 31 } 32 }

最近數學課上學習了矩陣,於是就寫了一個和矩陣有關的程式碼。希望大家多多支援,有問題私信我!