Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.forge;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Map<Integer, Integer> contador = new HashMap<Integer, Integer>();
- Scanner in = new Scanner(System.in);
- while (true) {
- System.out.println("ingrese numero entre 1 y 10. -1 para salir");
- int x = in.nextInt();
- if (x == -1) break;
- if (x < 1 || x > 10) {
- System.out.println("número inválido");
- continue;
- }
- System.out.println("control while");
- if (contador.containsKey(x)) {
- contador.put(x, contador.get(x) + 1);
- } else {
- contador.put(x, 1);
- }
- }
- for (int x = 1; x <= 10; x++) {
- System.out.println(x + " : " + contador.getOrDefault(x, 0));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement