Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JavaApplication26;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.HashMap;
- import java.util.Scanner;
- import java.util.Set;
- public class JavaApplication26 {
- public static void main(String[] args) throws FileNotFoundException
- {
- Scanner sc=new Scanner (new File("input.txt"));
- HashMap<String,Integer> hash=new HashMap<String,Integer>();
- while(sc.hasNext())
- {
- String cuv=sc.next( );
- if(hash.containsKey(cuv))
- {
- hash.put(cuv,1+hash.get(cuv));
- }
- else hash.put(cuv,1);
- }
- Set<String> Keys=hash.keySet();
- for(String var: Keys)
- {
- System.out.println(var+" "+hash.get(var));
- }
- //Set<Entry<String.Integer>>entries
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment