I am struggling with a beginning Java class. I have to modify a program to replace a user-generated integer array with a Random() number generated double precision floating point array.
This is what I have so far. I think it is generating the correct dataset, but I can't get the PrintWriter section configured correctly.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assign6array;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.util.Random;
/**
*
* @author matthew.neesley
*/
public class Assign6Array {
/**
* @param args the command line arguments
* @throws java.io.FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException {
// TODO code application logic here
int[] array = new int[10];
int count = 0;
int numbers = 0;
Random rd = new Random(); // creating Random object
double[] arr = new double[10];
for (int i = 0; i < array.length; i++) {
arr[i] = rd.nextInt(); // storing random integers in an array
while (numbers!= -1 && count <= 9)
{
array[count] = numbers;
count++;
System.out.println(arr[i]); // printing each array element
PrintWriter writer = new PrintWriter(System.out);
printr.print(arr[i]);
}
}
}
}
You are creating
PrintWriterlike thisThe variable is named
writer, but you use it like this:Using
printrvariable which doesn't exist. Do simply:Also, you need
PrintStreamacts as a buffer, so you will have to flush it's contents so that they are written to the output stream.