Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:52:55+00:00 2026-06-14T12:52:55+00:00

I am trying to to write randomly created doubles to a txt file, but

  • 0

I am trying to to write randomly created doubles to a txt file, but I do not know the best way of doing this since the doubles must be written to the file repeatedly

Here is my code for the Generator

public class DataGenerator 
{
  public static void main(String[] args) 
  {
    // three double values are read from command line m, b, and num
    double m = Double.parseDouble(args[0]); // m is for slope
    double b = Double.parseDouble(args[1]); // b is y-intercept
    double num = Double.parseDouble(args[2]); // num is number of x and y points to create
    double x = 0;
    double y = 0;
    for (double count = 0; count < num; count++) // for loop to generate x and y values
    {
      x = Math.random() * 100;
      y = (m * x) + b; // slope intercept to find y
      System.out.printf("\n%f , %f", x, y);
      System.out.println();
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:52:57+00:00Added an answer on June 14, 2026 at 12:52 pm

    There are number of thing you can use to write to a file. They basically all work the same way as System.out.. they just connect to a file instead of stdout. I would suggest taking a look at PrintWriter, IIRC that was one of the easier ones for a task like that

    PrintWriter fout= new PrintWriter("OutputFile.txt");
    //....
    fout.printf("\n%f , %f",x,y);
    fout.println();
    //....
    fout.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn the best way to write queries. I also understand
I am trying to write a function that will randomly return an (x,y) co-ordinates
I am trying write a function that generates simulated data but if the simulated
Trying to write a couple of functions that will encrypt or decrypt a file
Trying to write out syslog entries containing strings but they don't register. // person.name
I've been trying to get this program to work, but when I try to
I'm trying to write a simple Javascript(jQuery) function that randomly displays 6 Divs out
I'm doing a little experiment trying to randomly place images inside a div using
I'm trying to store randomly generated dice values in some data structure, but don't
I'm trying to write a simple ASCII style game with randomly generated world for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.