Java Programs
/**
* @author +Java Script
* Top 3 words from sentence
*/
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class SentenceWord {
public static void main(String[] args) {
Map<String,Integer> map = new HashMap();
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
for(String s: str.split("\\s")){
if(map.containsKey(s)){
int a = map.get(s);
a = a+1;
map.put(s,a);
}else{map.put(s,1);}
}
System.out.println(map);
}}
http://javabelazy.blogspot.in/
No comments:
Post a Comment
Your feedback may help others !!!