![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/63d0f703918fa0ecd9bf0629219759ee3d6ddb9e?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class NumCount {
static final String FILE_PATH = "f:\\test.txt";
public static void main(String[] args) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(FILE_PATH));//输出流
int index =0;//保存数字个数
for (int i = 1; i < 100; i++) {
if(i%3==0||i%7==0){//能被3或者7整除
index++;
bw.write(String.valueOf(i)+"\t");
if(index%5==0){ //每5个数字,换一行
bw.newLine();//换行
}
}
}
bw.close();//关闭流
System.out.println("结果保存到"+FILE_PATH+"完毕!");
} catch (IOException e) {
e.printStackTrace();
}
}
}