What Is Programming Solution 1

From CompSciWiki
Jump to: navigation, search

COMP 1010 Home > What_Is_Programming_Questions


Introduction

An exercise to print a poem.

   

{{{Body}}}

What do you need to know?

  • The words and punctuation of a 4-line poem; for example:
The Moving Finger writes; and, having writ,
Moves on: nor all thy Piety nor Wit
     Shall lure it back to cancel half a Line,
Nor all thy Tears wash out a Word of it.

 (from The Rubaiyat of Omar Khayyam, by Omar Khayyam, 11th Century / Translated by Edward FitzGerald)
  • How to print out a single line of output at a time.
  • How to put a sequence of output instructions in order.

Inputs

No inputs are required.

Outputs

  • The lines of the poem as seen above.
  • You should probably print out the source too, as a citation.

Transformation

Since there is no input, no transformation of the input is required.

Solution

/**................................................................PrintPoem
  * Print a 4-line poem
  * COMP1010 Exercise (What Is Programming?)
  * @author Terry Andres 
  * @version 2009-Sep-08
  */
public class PrintPoem {   
  
  /**...................................................................main
   * Required method.
   */
  public static void main( String[] args ) {
    System.out.println("The Moving Finger writes; and, having writ,") ;
    System.out.println("Moves on: nor all thy Piety nor Wit") ;
    System.out.println("  Shall lure it back to cancel half a Line,") ;
    System.out.println("Nor all thy Tears wash out a Word of it.") ;
    System.out.println() ;
    System.out.println("(from The Rubaiyat of Omar Khayyam, " +
                       "by Omar Khayyam, 11th Century " +
                       "/ Translated by Edward FitzGerald)" ) ;
    
  }
}

Template loop detected: Template loop detected: