package 数组练习;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class Demo {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Random r = new Random();
int[] arr = new int[10];
List<Integer> list = new ArrayList<Integer>();
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
int i = 0;
int count = 0;
while (i <= 9) {
arr[i] = r.nextInt(100) + 1;
i++;
}
for (int j = 0; j < arr.length; j++) {
if (arr[j] >= 10) {
list.add(arr[j]);
} else {
map.put(count++, arr[j]);
}
}
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println(entry.getKey() + "***" + entry.getValue());
}
for (Integer integer : list) {
System.out.println(integer);
}
FileWriter fw= new FileWriter("numbwer.txt");
for(int e=0;e<arr.length;e++){
fw.write(arr[e]+"\r\n");
fw.flush();
}
fw.close();
}
}
|