• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Haiku Generating Program

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Define "\n didn't work", it pretty much has to--"\n" is the newline character.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic