save file to disk java

public class Test {

   static final String[] conjunction = { "and", "or", "but", "because"};

   static final String[] proper_noun = { "Fred", "Jane", "Richard Nixon","Miss America"};

   static final String[] common_noun = { "man", "woman", "fish", "elephant", "unicorn"};                                  

   static final String[] determiner = { "a", "the", "every", "some"};

   static final String[] adjective = { "big", "tiny", "pretty", "bald"};

   static final String[] intransitive_verb = { "runs", "jumps", "talks", "sleeps"};

   static final String[] transitive_verb = { "loves", "hates", "sees", "knows", "looks for", "finds"};

  

  public static void main(String[] args) {

      while (true) {

         randomSentence();

      System.out.println(".\n");

         try {

             Thread.sleep(3000);

         }

         catch (InterruptedException e) {

         }

      }

   }

   static void randomSentence() {

      randomNounPhrase();

              randomVerbPhrase();

      if (Math.random() > 0.75) {

              System.out.print(" " + randomItem(conjunction));

              randomSentence();

      }

   }

   static void randomNounPhrase() {

          if (Math.random() > 0.75)

             System.out.print(" " + randomItem(proper_noun));

          else

          {

             System.out.print(" " + randomItem(determiner));

             if (Math.random() > 0.5)

         System.out.print(" " + randomItem(adjective)+".");

                System.out.print(" " + randomItem(common_noun));

                 if (Math.random() > 0.5){

                      System.out.print(" who" );

                      randomVerbPhrase();

                 }

          }

     }

      static void randomVerbPhrase() {

          if (Math.random() > 0.75)

             System.out.print(" " + randomItem(intransitive_verb));

                else if (Math.random() > 0.50) {

                        System.out.print(" " + randomItem(transitive_verb));

                        randomNounPhrase();

                }

                else if (Math.random() > 0.25)

                    System.out.print(" is " + randomItem(adjective));

                else {

                    System.out.print(" believes that");

                    randomNounPhrase();

                    randomVerbPhrase();

                }

       }

   static String randomItem(String[] listOfStrings){

       return listOfStrings[(int)(Math.random()*listOfStrings.length)];

   }

}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source