import java.util.Scanner; import java.io.*; public class Part5{ public static int [][] getSubMat(int [][] data, int row, int col, int width, int height){ int [][] newMat = new int [height][width]; for(int g = 0; g < newMat.length ; g++){ for(int h = 0; h < newMat.length; h++){ for(int i = row; i < height +row; i++){ for(int j = col; j < width+col; j++){ newMat[g][h]=data[i][j]; } } } } return null; } public static void main (String [] args){ Scanner input = new Scanner(System.in); int [][] list = {{1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15}, {16,17,18,19,20}}; getSubMat(list,1,2,2,2); } }
im trying to extract this matrix and putting into a submatrix but i keep getting 14 on every location of the new matrix... help... but when i go..
on my for loop. i get exactly the numbers that i want.. helpfor(int i = row; i < height +row; i++){ for(int j = col; j < width+col; j++){ System.out.printf("%2d" + " " ,data[i][j]); } }