Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program which reads integers from 1-100 and counts the occurances of eac

ID: 3760821 • Letter: W

Question

Write a program which reads integers from 1-100 and counts the occurances of each, an example: 8,4,4,2,1,3,7,7,0 and the results should be like: 8 occurs once 4 occurs twice 2 occurs once 1 occurs once 3 occurs once 7 occurs twice 0 occurs once
This program must be made in Python. Write a program which reads integers from 1-100 and counts the occurances of each, an example: 8,4,4,2,1,3,7,7,0 and the results should be like: 8 occurs once 4 occurs twice 2 occurs once 1 occurs once 3 occurs once 7 occurs twice 0 occurs once
This program must be made in Python. 8 occurs once 4 occurs twice 2 occurs once 1 occurs once 3 occurs once 7 occurs twice 0 occurs once
This program must be made in Python.

Explanation / Answer

import java.util.HashMap; import java.util.Map; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; public class Q21871053 { public static void main(final String[] args) { final Random rnd = new Random(); final Map counter = new HashMap() { @Override public AtomicInteger get(final Object key) { if (!super.containsKey(key)) { super.put((Integer) key, new AtomicInteger(rnd.nextInt(100))); } return super.get(key); } }; final AtomicInteger nextInt = new AtomicInteger(rnd.nextInt(100)); while (nextInt.get() != 0) { counter.get(nextInt.get()).incrementAndGet(); if (counter.size() > 100) { nextInt.set(0); } else { nextInt.set(rnd.nextInt(100)); } } for (final Integer i : counter.keySet()) { final AtomicInteger integer = counter.get(i); final String format = integer.get() > 1 ? "%d occurs %s times " : "%d occurs %s time "; System.out.format(format, i, integer); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote