Advertisements
I wrote the program and i want some help pleas this program check between if they are related or not . i have no problem of reading file and inserted in 2d array but i have wrote program to sum the ones each rows and compared to the second matrix and so that about coulmns , note : two matrix are not equal ! ,, so i will compared the small one with the bigger one so that i use start point and end point , i need only help to write the two method which sum rows and coulmns,
4
**0 0 0 0
1 1 1 1
1 1 0 0
1 1 1 1**
6
0 1 1 1 1 0
0 0 0 0 0 0
1 1 1 1 1 0
1 1 1 0 0 0
1 1 1 1 1 1
1 1 1 1 1 1
my work is
public static void main(String[] args) { try { Scanner sc = new Scanner(new File("zoo")); int caseOne = sc.nextInt(); int count=0 ; while(caseOne>=count) { //read the first matrix size. int length1=sc.nextInt(); int sum=0; System.out.println(length1); int[][] m1 = new int[length1][length1]; // print array in rectangular form for (int r=0; r<m1.length; r++) { for (int c=0; c<m1[r].length; c++) { m1[r][c]=sc.nextInt(); System.out.print(" " + m1[r][c]); } System.out.println(""); } // case two int length2=sc.nextInt(); System.out.println(length2); int[][] m2 = new int[length2][length2]; // print array in rectangular form for (int r=0; r<m2.length; r++) { for (int c=0; c<m2[r].length; c++) { m2[r][c]=sc.nextInt(); { System.out.print(" " + m2[r][c]); } } for (int a=0; a<m2.length; a++) { for (int c=0; c<m2[a].length; c++) { int startPoint= m2[r][c]-m1[r][c]/2; System.out.print(" " + startPoint); int EndPoint= m2[r][c]-startPoint; System.out.print(" " + EndPoint); } System.out.println(""); } count++; } } } catch (Exception e) { System.out.println(e); } } public static int sumRow( int[][] m1,int startPoint,int ei, int A[]) { return A[i]; } public static int sumcol(int m2[][],int si,int ei, int B[]) { int i=0 ; return B[i]; }
}
sorry for my weak english