java - 将随机数组输出到文件

标签 java arrays file-io printwriter

我正在尝试编写一个程序,该程序采用 200 个数字 (1-200) 的数组,将它们随机化,然后将这些数字输出到文本文件。

我一整天都在苦苦挣扎,但我不明白为什么没有任何效果。

主要方法:

public static void main (String[] args) 
{
    int[] numbers= new int [201];

    for (int i=0; i < numbers.length; i++)
    {
        numbers[i]=i;

    }
}//end main method

随机方法:

public static int[] randomizeArray(int[] numbers) 
{
    Random gen= new Random(10);

    for (int i=0; i < numbers.length; i++)
    {
        int n= gen.nextInt(200);
        numbers[i]=n;
    }

    return numbers;

}//end randomizeArray method

打印方法:

public static int[] outputArray(int[] numbers) throws IOException
{

    FileOutputStream output;

    output= new FileOutputStream("RandomOut.txt");

    new PrintStream(output).println(randomizeArray(numbers));

    output.close();

    return numbers;

}//end method outputArray

任何帮助都会很棒,我知道我忽略了某些事情或做错了事情。

最佳答案

您不应该在主方法的末尾调用outputArray吗?

关于java - 将随机数组输出到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8318321/

相关文章:

java - 在文件夹中保存图像时出现问题

将网络字节列表(big-endian)字节顺序存储到文件(little-endian)的Python方法

bash - 将多个 stdout 命令重定向到一个文件

java - Java中的色轮给出N个等距颜色

java - JFrame 中的标题居中对齐

ios - Objective C 如何读取嵌套的 JSON

java - 打印数组条目时出现空指针异常

java - jsp JSTI foreach : array from request. setAttribute

java - Java 编号 "casting"中的任何显着差异

c - C 语言的交互式随机程序