- 1、本文档共15页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
JAVA小练习
Problem A 计算数字出现次数
Problem Description
编写程序,读取在1到100之间的整数,然后计算每个数出现的次数。假定输入是以0结束的。
注意:如果一个数的次数大于一次,就在输出时使用复数“times”。
测试示例
Test Case 1:
Input 2 5 6 5 4 3 23 43 2 0 Output 2 occurs 2 times
3 occurs 1 time
4 occurs 1 time
5 occurs 2 times
6 occurs 1 time
23 occurs 1 time
43 occurs 1 time Test Case 2:
Input 2 5 7 5 4 3 7 2 0 Output 2 occurs 2 times
3 occurs 1 time
4 occurs 1 time
5 occurs 2 times
7 occurs 2 time Test Case 3:
Input 1 2 5 6 2 0 Output 1 occurs 1 time
2 occurs 2 times
5 occurs 1 time
6 occurs 1 time Test Case 4:
Input 1 5 6 5 4 4 23 1 0 Output 1 occurs 2 times
4 occurs 2 time
5 occurs 2 times
6 occurs 1 time
23 occurs 1 time Test Case 5:
Input 2 4 3 2 0 Output 2 occurs 2 times
3 occurs 1 time
4 occurs 1 time 程序代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Scanner;
public class NumberCount {
public static void main(String[] args) {
// TODO code application logic here
int[] NumberArray = new int[101];
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
int temp = input.nextInt();
if (temp == 0) break;
NumberArray[temp]++;
}
for (int i = 1; i NumberArray.length; i++) {
if (NumberArray[i] == 1)
System.out.println(i + occurs + NumberArray[i] + time);
if (NumberArray[i] 1)
System.out.println(i + occurs + NumberArray[i] + times);
}
}
}
Problem B 相同的数组
Problem Description
如果两个数组list1和list2的内容相同,那么就说他们是相同的。使用下面的方法头编写一个方法,如果list1和list2是相同的,该方法就返回true:
public static boolean equal(int[] list1, int[] list2);
编写一个测试程序,提示用户输入两个整数数列,然后显示他们两个是否相同。
测试示例
Test Case 1:
Input 5 2 5 6 6 1
5 5 2 6 1 6 Output Two lists are identical Test Case 2:
Input 5 2 5 6 6 1
5 5 2 6 1 3 Output Two lists are not identical Test Case 3:
Input 5 5 5 6 6 1
5 2 5 6 1 6 Output Two lists are not identical Test Case 4:
Input
您可能关注的文档
- 必威体育精装版人教版三年级下册Unit3 A talk 精品教案.doc
- 考研英语 2013 Text 1.doc
- 剑桥国际少儿英语1第7单元文本.doc
- 三年级下册PEP第3-4单元知识点总结及单元练习.doc
- 七年级英语第5689单元复习题.doc
- 推荐信常用的句型.doc
- 2012艺音乐表演本专科13-14期中考试英语综合英语试卷.doc
- 2012考研英语词汇速记宝典(纯英文狂背版).doc
- 专接本英语试题(一).doc
- 从唯物矛盾观的发展看马克思主义中国化创新的路径.docx
- 2024-2025学年小学英语三年级下册闽教版(三起)(2024)教学设计合集.docx
- 2024-2025学年中职数学基础模块上册高教版(第三版·李广全)教学设计合集.docx
- 2024-2025学年高中物理第一册沪科版(2020·上海专用)教学设计合集.docx
- 2024-2025学年高中历史第一册华师大版教学设计合集.docx
- 2024-2025学年小学信息技术(信息科技)四年级上册电子工业版(内蒙古)教学设计合集.docx
- 2024-2025学年高中语文选修三 诗歌 散文 小说北京版教学设计合集.docx
- 2024-2025学年中职思想政治经济政治与社会(第4版)北师大版教学设计合集.docx
- 2024-2025学年中职中职专业课汽车制造与维修类66 装备制造大类教学设计合集.docx
- 2024-2025学年小学英语一年级下册牛津上海版(深圳用)(2024)教学设计合集.docx
- 2024-2025学年初中美术八年级上册人教版(2024)教学设计合集.docx
文档评论(0)