storing file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • java2sun
    New Member
    • Feb 2008
    • 1

    storing file

    hi i've got this code, I want to store this in a file and the output will be

    "1*2*4*5*6*8*9* 10"

    can anyone plz help me to find this out...

    here is the code

    Code:
    public String printPositive Integers()
    {
    for(int i=1; i<=10; i++)
    {
    System.out.prin t("*"+i);
    }
    }
  • jimhawkss
    New Member
    • Feb 2008
    • 10

    #2
    A good place to start would be Importing
    java.io.*;

    You are going to want to read some of Sun's tutorials involving Buffered Reader, and Outfiles.

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      Originally posted by java2sun
      hi i've got this code, I want to store this in a file and the output will be

      "1*2*4*5*6*8*9* 10"

      can anyone plz help me to find this out...

      here is the code

      Code:
      public String printPositive Integers()
      {
      for(int i=1; i<=10; i++)
      {
      System.out.prin t("*"+i);
      }
      }
      By the way, that code will give you
      Code:
      *1*2*3*4*5*6*7*8*9*10
      (so there's an extra * at the beginning.)
      To solve this, you could use an if-section in the loop or write the first number outside of the loop or...

      Also, about writing files, this Howto could be what you're looking for. (Although of course, Sun's tutorials are much bigger and therefore you can learn much more.)

      Greetings,
      Nepomuk

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        You can always redirect stdout from the command line:

        Java YourProgram > stdout.txt

        Comment

        Working...