Write a program that reads in a set of positive integers and outputs how many times a particular number appears in the list. You may assume that the data set has most 7 numbers
The numbers must be output in increasing order for example:
15402862621528
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args) {
System.out.println("Enter the list:");
Scanner scanner = new Scanner(System.in);
List<Integer> _inputs = new ArrayList<>();;
for(int i=0; i<7; i++){
_inputs.add(Math.abs(Integer.parseInt(scanner.nextLine())));
}
scanner.close();
Set<Integer> uniqueSet = new HashSet<Integer>(_inputs);
for (Integer temp : uniqueSet) {
System.out.println(temp + ": " + Collections.frequency(_inputs, temp));
}
}
}
Comments
Leave a comment