本周收获:
获取一定范围内的随机数:
public static int random_num(int a,int b) { int c=(int) (Math.random()*(b-a+1)); return c+a; }
将信息写入到TXT文档:
public static void WriterFun(){ //获得路径 File file = new File("input.txt"); if(!file.exists()){//判断file是否存在 try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } try { BufferedWriter bw = new BufferedWriter(new FileWriter(file)); for(int i=0;i<10000;i++){ int nums = random_num(-1000000,2000000); //将int 转化为 String类型 if(i!=0) bw.write(" "+Integer.toString(nums)); else bw.write(Integer.toString(nums)); //bw.newLine(); } bw.close(); } catch (IOException e) { e.printStackTrace(); } }