Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Haiku Generating Program

 
Tarun Durga
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tarun Durga
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define "\n didn't work", it pretty much has to--"\n" is the newline character.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic