SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Barbara Dolye
Chapter:
Introduction To Computing And Programming
Exercise:
Programming Exercises
Question:6 | ISBN:9781285096261 | Edition: 4

Question

Create an application that produces three different outputs using the same phrase. Select your own favorite popular saying for the phrase. The phrase should first be displayed on one line. Use at least three Write( ) methods - but the output should all appear on a single line.
Then print the phrase on three lines, again using only Write( ) methods. For your third and final output, print your favorite saying one word per line. Decide which combination of Write( ) and/or WriteLine( ) would be the most streamlined approach. Following is an example of what the final output would look like using a favorite saying of the author:

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program:

using System;
 
namespace ProgrammingExercise6
{
    class Program
    {
        static void Main(string[] args)
        {

           // First dispaly output
            Console.Write("Output #1");
            Console.Write("\nLaugh often. ");
            Console.Write("Dream big. ");
            Console.Write("Reach for the start! \n");
            

            // Second dispaly output           
            Console.Write("\nOutput #2");
            Console.Write("\nLaugh often. \n");
            Console.Write("Dream big. \n");
            Console.Write("Reach for the start! \n");

            // Third dispaly output
            Console.Write("\nOutput #3");
            Console.WriteLine("\nLaugh");
            Console.WriteLine("often.");
            Console.WriteLine("Dream");
            Console.WriteLine("big.");
            Console.WriteLine("Reach");
            Console.WriteLine("for");
            Console.WriteLine("the");
            Console.WriteLine("start!");
            Console.ReadKey();
        }
    }
}

Output:

Explanation:

* For Write method we have to use aruguments to split the string.

* For WriteLine method there is no need of using aruguments,spaces in between the string.

0 0

Discussions

Post the discussion to improve the above solution.