wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Haiku Generating Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Haiku Generating Program" Watch "Haiku Generating Program" New topic
Author

Haiku Generating Program

Tarun Durga
Greenhorn

Joined: Jun 17, 2009
Posts: 5
I've made a Haiku Generating Program... on the lines of PhraseOMatic example in Head first Java 2nd Edition (pg 16).

Problem: I need to have a line break after each of the 3 lines instead of all 3 in one line. I need something like:

Digital Haiku:
River flows singing
Like moth before burning flame
Over autumn red leaves

And I'm getting:

Digital Haiku: River flows singing Like moth before burning flame Over autumn red leaves.

Please help. What is the command to get line breaks in a program like this?

Here is the code I've written so far:



[edited to add code tags]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31101
    
165

You have two options. One is to use "\n" instead of a space when you create the phrase. The other is to call System.out.println() three times - one for each phrase.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Tarun Durga
Greenhorn

Joined: Jun 17, 2009
Posts: 5
Thanks Jeanne. Repeating println 3 times worked.

However, can you elaborate a little more on "\n"? That didn't work.

Cheers,
Tarun
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Define "\n didn't work", it pretty much has to--"\n" is the newline character.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Haiku Generating Program