Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package Demsotu;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Scanner;
- /**
- *
- * @author Anh-Kool
- */
- public class Demtu {
- public static void main(String[] args) throws IOException{
- HashMap<String, Integer> hm = new HashMap<String, Integer>();
- ArrayList<String> al = new ArrayList<String>();
- String duongdan;
- Scanner s = new Scanner(System.in);
- System.out.print("Mơi ban nhap duong dan tap tin: ");
- duongdan = s.nextLine();
- FileReader fr = new FileReader(duongdan);
- BufferedReader br = new BufferedReader(fr);
- String dong;
- while ((dong = br.readLine()) != null) {
- al.add(dong);
- }
- for (int i = 0; i < al.size(); i++) {
- String[] arr = al.get(i).split(" ");
- for (int j = 0; j < arr.length; j++) {
- String str = arr[j];
- if(!hm.containsKey(str)){
- hm.put(str, 1);
- }else{
- int n = hm.get(str).intValue();
- n++;
- hm.put(str, n);
- }
- }
- }
- System.out.println("Cac tu dem duoc la: ");
- for (String k : hm.keySet()) {
- Integer v = hm.get(k);
- System.out.println(k+ " : "+ v);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement