第1个回答 2013-03-19
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
*
*/
public class DbColorBall {
HashMap <String,String>map = new HashMap<String,String>();
private void getNums() {
Random r = new Random();
int i = r.nextInt(19);
String s;
if (i > 0 && !map.containsKey(String.valueOf(i))) {
if (i < 10) {
s = "0" + i;
} else {
s = String.valueOf(i);
}
map.put(String.valueOf(i), s);
} else {
getNums();
}
}
public void showResult(){
for(int i=0;i<7;i++){
getNums();
}
for(Map.Entry<String,String> entry :map.entrySet()) {
System.out.println(entry.getValue());
}
}
public static void main(String[] args) {
DbColorBall dbColorBall = new DbColorBall();
dbColorBall.showResult();
}
}本回答被提问者和网友采纳