Java??????????????????
???????????? ???????[ 2012/11/1 10:27:22 ] ????????
?????????????????????????????
import java.util.Random;
/**
* ??????????
* @Description:
* @File: Demo4.java
* @Package None
* @Author Hanyonglu
* @Date 2012-10-18 ????06:27:38
* @Version V1.0
*/
public class Demo4 {
public static void main(String[] args) {
int[] values = new int[20];
Random random = new Random();
for(int i = 0;i < values.length;i++){
int number = random.nextInt(100) + 1;
for(int j = 0;j <= i;j++){
if(number != values[j]){
values[i]=number;
}
}
}
// ???????鰱???????
for(int i = 0;i < values.length;i++){
System.out.print(values[i] + " ");
if(( i + 1 ) % 10 == 0){
System.out.println("
");
}
}
}
}
????????????????????Ч?????????????????????????????μ???б???????????????????臨?????O(N^2)??????????????????£?????漰?????????????????????HashSet??HashMap??????HashSet???Set????Set????????????????????????????????HashMap???Map???????????????Key????????????????HashMap??HashSet??????
?????????HashMap????????????????key?????????Ok??????′???
import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
import java.util.Map.Entry;
/**
* ???HashMap???
* @Description:
* @File: Demo.java
* @Package None
* @Author Hanyonglu
* @Date 2012-10-18 ????06:12:50
* @Version V1.0
*/
public class Demo {
public static void main(String[] args) {
int n = 0;
Object[] values = new Object[20];
Random random = new Random();
HashMap<Object?? Object> hashMap = new HashMap<Object?? Object>();
// ????????????????HashMap
for(int i = 0;i < values.length;i++){
int number = random.nextInt(100) + 1;
hashMap.put(number?? i);
}
// ??HashMap????????
values = hashMap.keySet().toArray();
// ???????鰱???????
for(int i = 0;i < values.length;i++){
System.out.print(values[i] + " ");
if(( i + 1 ) % 10 == 0){
System.out.println("
");
}
}
// Iterator iter = hashMap.entrySet().iterator();
// // ????HashMap
// while (iter.hasNext()) {
// Entry<Integer?? Integer> entry = (Entry)iter.next();
// int key = entry.getKey();
// n++;
//
// System.out.print(key + " ");
//
// if(n % 10 == 0){
// System.out.println("
");
// }
// }
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11