zoukankan      html  css  js  c++  java
  • 2020.8.29

    一、今日学习内容

      1、将1000以内所有的素数输出到C盘根目录文件Prime.txt中,每一行只输出一个素数。将程序和输出文件一起打包。

     1 import java.io.FileWriter;
     2 import java.io.IOException;
     3 public class SuShu {
     4     public static void main(String[] args)throws IOException {
     5         writefile();
     6     }
     7     public static void writefile()throws IOException{
     8         int k=0,m,n;
     9         FileWriter filew=new FileWriter("C:/Prime.txt",true);
    10         for(int i=2;i<=1000;i++) {
    11             m=0;n=0;
    12             for(int j=2;j<i;j++) {
    13                 m=i%j;
    14                 if(m==0)break;
    15                 if(m!=0)n++;
    16             }
    17             if(n==i-2) {
    18                 filew.write(String.valueOf(i)+"\n");
    19                 System.out.println(i);
    20             }
    21         }
    22         filew.close();
    23     }
    24 }

    二、遇到的问题

        想文件中写入数字不是很清楚

    三、明日计划

        继续完成相关例题

  • 相关阅读:
    codeforces 980A Links and Pearls
    zoj 3640 Help Me Escape
    sgu 495 Kids and Prizes
    poj 3071 Football
    hdu 3853 LOOPS
    hdu 4035 Maze
    hdu 4405 Aeroplane chess
    poj 2096 Collecting Bugs
    scu 4444 Travel
    zoj 3870 Team Formation
  • 原文地址:https://www.cnblogs.com/wmdww/p/13583680.html
Copyright © 2011-2022 走看看