MapReduce計算每一年最大值測試樣例生成程序

 

Demo.javahtml

 

package com.java;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

/**
 * 隨機生成從2000到2018天天一個隨機四位數,用於MapReduce計算每一年最大值測試
 * 
 * @author Logan
 * @createDate 2019-03-18
 * @version 1.0.0
 *
 */
public class Demo {

    /**
     * 生成文件存放在D盤1.txt
     */
    private static final String PATH = "D:\\1.txt";

    private static final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");

    public static void main(String[] args) {
        File file = new File(PATH);

        try (
                FileWriter writer = new FileWriter(file);
                BufferedWriter bufWriter = new BufferedWriter(writer);
        ) {

            if (!file.exists()) {
                file.createNewFile();
            }

            Calendar start = Calendar.getInstance();
            Calendar end = Calendar.getInstance();
            start.set(2000, 0, 1);
            end.set(2018, 0, 1);

            StringBuffer line = null;
            while (start.before(end)) {
                line = new StringBuffer();
                line.append(format.format(start.getTime()));
                line.append(getRandom()).append("\n");
                bufWriter.write(line.toString());
                start.add(Calendar.DATE, 1);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 隨機生成一個四位整數
     * 
     * @return
     */
    private static int getRandom() {
        Random r = new Random();
        return r.nextInt(9000) + 1000;
    }

}

 

 

計算程序參見:java

http://www.javashuo.com/article/p-uwqbabwa-mm.htmlapp

 

.dom

相關文章
相關標籤/搜索