长度不相等则补零,对应位置元素大的个数多的数组大
输入
2//数组长度
1 2
3
2 1 -1
输出
ture//数组1比数组2大的元素多
java在一个类中写方法比较两个int形数组大小
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- Tomshidi 2022-03-07 22:52关注
public static void main(String[] args) { Scanner s = new Scanner(System.in); int countMax1 = 0; int countMax2 = 0; int arrSize1 = s.nextInt(); int[] arr1 = new int[arrSize1]; for (int i = 0; i < arrSize1; i++) { arr1[i] = s.nextInt(); } int arrSize2 = s.nextInt(); int[] arr2 = new int[arrSize2]; for (int i = 0; i < arrSize2; i++) { arr2[i] = s.nextInt(); } int loopSize = Math.max(arrSize1, arrSize2); for (int i = 0; i < loopSize; i++) { int arrItem1 = 0; int arrItem2 = 0; if (i < arrSize1) { arrItem1 = arr1[i]; } if (i < arrSize2) { arrItem2 = arr2[i]; } if (arrItem1 > arrItem2) { countMax1++; } if (arrItem2 > arrItem1) { countMax2++; } } System.out.println(countMax1 > countMax2); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1
悬赏问题
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改