sorting - Using map in java -


i working on app reads set of ints console , creates map each unique int. counts how many times input occurs , prints out ordered tally. have gotten far , having hard time moving forward here.

package examprep;  import java.awt.list; import java.awt.point; import java.util.arraylist; import java.util.hashmap; import java.util.map; import java.util.scanner; import java.util.set;  import javax.swing.text.html.htmldocument.iterator;  public class mapthatreadsints {      public static void main(string[] args) {         // based on problem gave in class          scanner input = new scanner(system.in);          system.out.println("please enter integer");         int inputvalue = input.nextint();          hashmap<integer, integer> numbermap = new hashmap<integer, integer>();          numbermap.put(inputvalue, inputvalue);          system.out.println("size of map " + numbermap.size());     } } 

i know have use arraylist here somewhere , loop iterate on each input. having hard time figuring out how that. sort of appreciated. thanks. :)

i'm guessing homework don't want detailed...

  1. presumably in loop somehow, user can enter many integers. want create ("new") hashmap outside of loop, not inside seems now. otherwise hold recent integer.

  2. within loop, if integer in hashmap, need handle differently if first time entered. think that.

  3. since want print them out in order, use treemap instead keeps them in sorted order.

hope gets started bit more along right path...


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -