package chapter07;
import java.util.*;
/**
* @author mazouri
* @create 2020-03-25 14:44
*/
public class Question03 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the integers between 1 and 100(0结束): ");
HashMap<Integer, Integer> hashMap = new HashMap<>();
int number = input.nextInt();
while (number != 0) {
if (number <= 100 && number >= 0) {
if (hashMap.containsKey(number)) {
hashMap.put(number, hashMap.get(number) + 1);
} else {
hashMap.put(number, 1);
}
}
number = input.nextInt();
}
//打印输出
hashMap.forEach((value, times) -> System.out.println(value + " occurs " + times + ((times == 1) ? " time " : " times ")));
}
}
运行结果