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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26195
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
posted Jun 20, 2009 08:36:26
0
Define "\n didn't work", it pretty much has to--"\n" is the newline character.
subject: Haiku Generating Program