import java.util.*;
//这个代码里的数字是怎么生成的,还是不太理解
public class hh {
public static void main(String[] args){
HashMap h1=new HashMap();
Random r1=new Random();
for(int i=0;i<100;i++){
Integer t=new Integer(r1.nextInt(20));
if(h1.containsKey(t)){//如果包含指定的映射关系
((Ctime)h1.get(t)).count++;
//System.out.println("==="+((Ctime)h1.get(t)).count++);
}
else{
h1.put(t, new Ctime());//指定key和value
//System.out.println("---"+new Ctime());
}
}
System.out.println(h1);
}
}class Ctime{
int count=0;
public String toString(){
return Integer.toString(count);
}
}
运行结果如下,我不明白的是HaspMap里的数据是怎么产生的,看起来是随机的
{15=7, 4=5, 19=4, 8=6, 11=3, 16=2, 18=4, 3=4, 7=5, 12=6, 17=1, 2=0, 13=5, 9=1, 6=9, 1=0, 14=3, 10=2, 5=7, 0=6}
//这个代码里的数字是怎么生成的,还是不太理解
public class hh {
public static void main(String[] args){
HashMap h1=new HashMap();
Random r1=new Random();
for(int i=0;i<100;i++){
Integer t=new Integer(r1.nextInt(20));
if(h1.containsKey(t)){//如果包含指定的映射关系
((Ctime)h1.get(t)).count++;
//System.out.println("==="+((Ctime)h1.get(t)).count++);
}
else{
h1.put(t, new Ctime());//指定key和value
//System.out.println("---"+new Ctime());
}
}
System.out.println(h1);
}
}class Ctime{
int count=0;
public String toString(){
return Integer.toString(count);
}
}
运行结果如下,我不明白的是HaspMap里的数据是怎么产生的,看起来是随机的
{15=7, 4=5, 19=4, 8=6, 11=3, 16=2, 18=4, 3=4, 7=5, 12=6, 17=1, 2=0, 13=5, 9=1, 6=9, 1=0, 14=3, 10=2, 5=7, 0=6}
楼主【zzzkkk666】截止到2008-08-02 14:44:22的历史汇总数据(不包括此帖):
发帖的总数量:35 发帖的总分数:857 每贴平均分数:24
回帖的总数量:111 得分贴总数量:14 回帖的得分率:12%
结贴的总数量:35 结贴的总分数:857
无满意结贴数:3 无满意结贴分:70
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:8.57 % 无满意结分率:8.17 %
敬礼!
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=zzzkkk666
import java.util.*;
public class hh {
public static void main(String[] args){
HashMap h1=new HashMap();
Random r1=new Random(); ------大哥,你这不让她随即产生的么,当然是随即出来的啊
for(int i=0;i<100;i++){------------循环了100下,就随即产生了100个呗。
Integer t=new Integer(r1.nextInt(20));----------转成int型
if(h1.containsKey(t)){//如果包含指定的映射关系
((Ctime)h1.get(t)).count++;//然后相应的value值++,
//System.out.println("==="+((Ctime)h1.get(t)).count++);
}
else{
h1.put(t, new Ctime());//指定key和value //如果不存在,就添加上。
//System.out.println("---"+new Ctime());
}
}
System.out.println(h1);
}
}class Ctime{
int count=0;
public String toString(){
return Integer.toString(count);
}
}------------------------------------
这个题的意思就是,让你随即产生100个20以内的数字,然后让你给出每个随即数产生的次数,而map中key是不运行有重复的,所以就添加到map中,一边添加,一边判断。
o了。。
取的随机数,得到的当然是随机的了。
。
无语