Chotucode
<p>import java.util.Scanner;</p>
<p>public class MatrixSumCalculator {</p>
<p> public static void main(String[] args) {<br />
Scanner scanner = new Scanner(System.in);</p>
<p> // Read the size of the matrix<br />
int n = scanner.nextInt();</p>
<p> // Create a matrix to store the integers<br />
int[][] matrix = new int[n][n];</p>
<p> // Read the matrix from input<br />
for (int i = 0; i < n; i++) {<br />
for (int j = 0; j < n; j++) {<br />
matrix[i][j] = scanner.nextInt();<br />
}<br />
}</p>
<p> // Calculate the sum of each row<br />
int[] rowSums = new int[n];<br />
for (int i = 0; i < n; i++) {<br />
int rowSum = 0;<br />
for (int j = 0; j < n; j++) {<br />
rowSum += matrix[i][j];<br />
}<br />
rowSums[i] = rowSum;<br />
}</p>
<p> // Calculate the sum of each column<br />
int[] columnSums = new int[n];<br />
for (int j = 0; j < n; j++) {<br />
int columnSum = 0;<br />
for (int i = 0; i < n; i++) {<br />
columnSum += matrix[i][j];<br />
}<br />
columnSums[j] = columnSum;<br />
}</p>
<p> // Output the results<br />
System.out.println("Line Sums:");<br />
for (int sum : rowSums) {<br />
System.out.print(sum + " ");<br />
}<br />
System.out.println();</p>
<p> System.out.println("Column Sums:");<br />
for (int sum : columnSums) {<br />
System.out.print(sum + " ");<br />
}<br />
System.out.println();</p>
<p> scanner.close();<br />
}<br />
}</p>