package jun2;
/*
* Find the sum of each row and each column of n x m of 2D Matrix
*
*/
public class SumOf2DMatrixRowsAndColumn {
public static void main(String[] args) {
int [][] twoDMatrix = {{ 20, 18, 23, 20, 16 },
{ 30, 20, 18, 21, 20 },
{ 16, 19, 16, 53, 24 },
{ 25, 24, 22, 24, 25 }
};
outputArray(twoDMatrix);
}
public static void outputArray(int[][] array) {
int sum= 0;
int rowSize = array.length;
int[] colSum =new int[array[0].length];
for (int i = 0; i < array.length; i++){
for (int j = 0; j < array[i].length; j++){
sum += array[i][j];
colSum[j] += array[i][j];
}
System.out.println("sum of rows "+ i +" = " + sum);
}
System.out.println(" ");
for(int k=0;k<colSum.length;k++){
System.out.println("sum of columns "+ k +" = " + colSum[k]);
}
}
}
/*output:
sum of rows 0 = 97
sum of rows 1 = 206
sum of rows 2 = 334
sum of rows 3 = 454
sum of columns 0 = 91
sum of columns 1 = 81
sum of columns 2 = 79
sum of columns 3 = 118
sum of columns 4 = 85
*/
A blog about new technology, Android, iOS, Mobile Automation, Appium, Web Automation, Selenium, JAVA, Shell Scipting, Powershell, Testing Tools, QA, Spring Boot, Free Software, How to design best frameworks etc..
Java : Program to find the sum of each row and each column of n x m of 2D Matrix
Subscribe to:
Post Comments (Atom)
πAnnouncement : Visit the new website/blog π
πππ Announcement : Visit the new website/blog πππ Dear readers, Thank you for reading my blog. If you could have used the little info...
-
How to find the UDID of Android Device What is UDID : It stands for Unique Device Identifier. UDID is required duri...
-
How to change language of device using commandLine Changing language in Android device on-the fly is needed when we are running or exe...
-
To setup Appium for mobile automation, you will need below items to be configured in your test environment. 1. Appium server : 1.1 D...
-
How to get the package name of Android application There are multiple ways in which we can obtain the package name of Android .apk file. ...
No comments:
Post a Comment