I have made a programme to count the number of words using HashMap.Here it is-:
import java.util.*;
class Count{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
String in=s.nextLine();
HashMap hm=new HashMap();
String sh[]=in.split(" ");
for(int i=0;i<sh.length;i++){
String key=sh[i];
if(sh[i].length() > 1){
if(hm .get(key)==null){
hm.put(key,i);
}
else{
int value=new Integer(hm.get(key).intValue());
value++;
hm.put(key,value);
}
}
}
System.out.println(hm);
}
}
しかし、このプログラムでは、jdk 1.6 を使用しているため、.intValue() シンボルが見つからないというエラーが発生しています。オートボクシングとアンボクシングの機能が追加されているので、それが問題だと思います。カウントを計算したいので、解決策を教えてください。 .