错误原因:
/*
* Multiple ers at this line
- Can only iterate over an array or an instance of java.lang.Iterable
- Map.Entry is a raw type. References to generic type Map<K,V>.Entry<K,V> should be
parameterized
*/
代码如下:
import java.util.HashMap;
import java.util.Map.Entry;public class TongJiZiFu { public static void main(String[] args){
String content = "中国aadf的111萨bbb菲的zz萨菲";
HashMap map = new HashMap();
for(int i=0;i<content.length();i++)
{
char c = content.charAt(i);
Integer num = (Integer)map.get(c);
if(num == null)
num = 1;
else
num = num + 1;
map.put(c,num);
}
for(Entry entry : map)
{
System.out.println(entry.getKey() +":" + entry.getValue());
}
}
}
其中标红色是出错的地方;for(Entry entry : map)
/*
* Multiple ers at this line
- Can only iterate over an array or an instance of java.lang.Iterable
- Map.Entry is a raw type. References to generic type Map<K,V>.Entry<K,V> should be
parameterized
*/
代码如下:
import java.util.HashMap;
import java.util.Map.Entry;public class TongJiZiFu { public static void main(String[] args){
String content = "中国aadf的111萨bbb菲的zz萨菲";
HashMap map = new HashMap();
for(int i=0;i<content.length();i++)
{
char c = content.charAt(i);
Integer num = (Integer)map.get(c);
if(num == null)
num = 1;
else
num = num + 1;
map.put(c,num);
}
for(Entry entry : map)
{
System.out.println(entry.getKey() +":" + entry.getValue());
}
}
}
其中标红色是出错的地方;for(Entry entry : map)
Set<Entry> entryset=map.entrySet();
for(Entry entry:entryset)
System.out.println(entry.getKey() +":" + entry.getValue());
import java.util.HashMap;
import java.util.Set;
import java.util.Map.Entry;public class TongJiZiFu { public static void main(String[] args) {
String content = "中国aadf的111萨bbb菲的zz萨菲";
HashMap map = new HashMap();
for (int i = 0; i < content.length(); i++) {
char c = content.charAt(i);
Integer num = (Integer) map.get(c);
if (num == null)
num = 1;
else
num = num + 1;
map.put(c, num);
}
Set<Entry> set = map.entrySet();
for (Entry entry : set) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
}
}
{
System.out.println(entry.getKey() +":" + entry.getValue());
}
这段代码能编译通过?