用java编一个程序,求100以内所有能被3整除或被7整除的数,并把结果写入f盘根目

如题所述

第1个回答  2017-08-09

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Administrator
 */
public class NewClass {

    public static void main(String[] args) throws IOException {
        byte i = 1;
        File file = new File("F:\\test.txt");
        System.out.println(file.isFile());
        FileWriter out = new FileWriter(file);
        while (i <= 100) {
            if (i % 3 == 0 || i % 7 == 0) {
                out.write(i + ",");
            }
            i++;
        }
        out.close();
    }
}

亲测有效