1.用Java编写程序,求下列二维数组中各行元素之和并查找其值最大的那个行。 数组在问题补充里
{23,45,65,34,21,67,78},{46,14,18,46,98,63,88},{98,81,64,90,21,14,23},{54,43,55,76,22,...
{23, 45, 65, 34, 21, 67, 78},
{46, 14, 18, 46, 98, 63, 88},
{98, 81, 64, 90, 21, 14, 23},
{54, 43, 55, 76, 22, 43, 33}; 展开
{46, 14, 18, 46, 98, 63, 88},
{98, 81, 64, 90, 21, 14, 23},
{54, 43, 55, 76, 22, 43, 33}; 展开
3个回答
展开全部
public static void main(String[] args) {
int[][] arr = {{23, 45, 65, 34, 21, 67, 78},{46, 14, 18, 46, 98, 63, 88},{98, 81, 64, 90, 21, 14, 23},{54, 43, 55, 76, 22, 43, 33}};
for (int i = 0; i < arr.length; i++) {
int total=0;
for (int j = 0; j < arr[i].length; j++) {
total += arr[i][j];
}
System.out.println("第"+i+"行的和为:"+total);
}
}
记录每行的下标以及和,然后用排序算法查找其最大行
int[][] arr = {{23, 45, 65, 34, 21, 67, 78},{46, 14, 18, 46, 98, 63, 88},{98, 81, 64, 90, 21, 14, 23},{54, 43, 55, 76, 22, 43, 33}};
for (int i = 0; i < arr.length; i++) {
int total=0;
for (int j = 0; j < arr[i].length; j++) {
total += arr[i][j];
}
System.out.println("第"+i+"行的和为:"+total);
}
}
记录每行的下标以及和,然后用排序算法查找其最大行
展开全部
int[][] s={{23, 45, 65, 34, 21, 67, 78},
{46, 14, 18, 46, 98, 63, 88},
{98, 81, 64, 90, 21, 14, 23},
{54, 43, 55, 76, 22, 43, 33}};
int[] sum=new int[4];
for(int i=0;i<s.length;i++){
for(int z=0;z<s[i].length;z++){
sum[i]+=s[i][z];
}
}
System.out.println(Arrays.toString(sum));<----印出所有和还未排列
Arrays.sort(sum);
System.out.println(Arrays.toString(sum));<----印出所有和并由小到大排列
{46, 14, 18, 46, 98, 63, 88},
{98, 81, 64, 90, 21, 14, 23},
{54, 43, 55, 76, 22, 43, 33}};
int[] sum=new int[4];
for(int i=0;i<s.length;i++){
for(int z=0;z<s[i].length;z++){
sum[i]+=s[i][z];
}
}
System.out.println(Arrays.toString(sum));<----印出所有和还未排列
Arrays.sort(sum);
System.out.println(Arrays.toString(sum));<----印出所有和并由小到大排列
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |