Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedHashMap;
- import java.util.Map.Entry;
- import java.util.Scanner;
- public class CouplesFrequency {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String sequence = input.nextLine();
- String[] numbers = sequence.split(" ");
- LinkedHashMap<String, Double> map = new LinkedHashMap<String, Double>();
- for (int i = 0; i < numbers.length - 1; i++) {
- String couple = numbers[i] + " " + numbers[i + 1];
- if (!map.containsKey(couple)) {
- map.put(couple, 1.0);
- } else {
- map.put(couple, map.get(couple) + 1.0);
- }
- }
- for (Entry<String, Double> entry : map.entrySet()) {
- System.out.printf("%s -> %.2f%%", entry.getKey(),
- (entry.getValue() / (numbers.length - 1)) * 100);
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement