1. 1、本文档共15页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 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

您可能关注的文档

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档