Advertisement
lpuarmy

Lat. 6 | ASD 01b

Sep 19th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. package lat6;
  2. import java.util.*;
  3.  
  4. /**
  5.  * @author yufieko
  6.  */
  7.  
  8. public class LatMap {
  9.     private static final Integer one = new Integer(1);
  10.     public static void main(String[] args) {
  11.         Scanner input = new Scanner(System.in);
  12.         String kalimat;
  13.         System.out.print("Masukkan kalimat anda : ");
  14.         kalimat = input.nextLine();
  15.        
  16.         String[] kata = kalimat.split("\\s+");
  17.         SortedMap data = new TreeMap();
  18.         for(int i=0; i<kata.length; i++){
  19.             Integer freq = (Integer) data.get(kata[i]);
  20.             //System.out.println(kata[i]);
  21.             data.put(kata[i], (freq == null ? one : new Integer(freq.intValue() + 1)));
  22.         }
  23.        System.out.println(data);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement