2020-04-28
2020-04-28 本文已影响0人
IT界汤哥看世界
问道友这个代码是干什么的
import java.util.*;
class Array
{int m, n;Scanner reader=new Scanner(System.in);int[][] arr;
void inputLen(){System.out.print("Please enter array row and column: ");m=reader.nextInt();n=reader.nextInt();arr=new int[m][n];}
int i, j;
void inputArr()
{System.out.println("Please enter "+m+"*"+n+" array: ");
for(i=0; i<m; i++)
for(j=0; j<n; j++)
arr[i][j]=reader.nextInt();}
void sumColumn()
{int[] colSum=new int[n];
for(j=0; j<n; j++){
for(i=0; i<m; i++)
colSum[j]+=arr[i][j];
System.out.println("Column"+(j+1)+" sum="+colSum[j]);}}}
public class App1
{public static void main(String[] args){
Array matrix=new Array();matrix.inputLen();matrix.inputArr();matrix.sumColumn();}
}