I cant get this to work properly it counts cumulative not per key
I have tried multiple ways of resetting count++ i cant seem to figure it out
This fixed it
int count = 0;
for (int i =0; i < intList.size(); i++){
if (map.containsKey(intList.get(i))){
map.put(intList.get(i), map.get(intList.get(i))+1);
}
}
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
/*
Longest sequence
*/
public class Solution {
public static void main(String[] args) throws IOException {
//Declare Lists
ArrayList<Integer> intList = new ArrayList<Integer>();
HashMap<Integer, Integer> map = new HashMap<>();
//Create an input buffer
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//Populate list with values from user
for (int i = 0; i < 10; i++){
intList.add(Integer.parseInt(reader.readLine()));
}
//Place elements of intList into a map as keys
// Note:duplicate keys are not allowed in map
for (int i = 0; i < intList.size(); i++){
map.put(intList.get(i), null);
}
/*
//Assign each key a count of how many elements in intList exist for each key
int count = 0;
for (int i =0; i < intList.size(); i++){
count = 0;
if (map.containsKey(intList.get(i))){
map.put(intList.get(i), count+++1);
}
}
*/
System.out.println(map);
}
}