Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday 19 July 2017

String based program


String program #16 (First reverse the string than make the even position character to upper case using ternary operator)

Enter String: imagination
O/p: -
Reverse String: noitanigami
Reverse String: NoItAnIgAm

The program for the string is written in C# programming language and will accept a string as input. The logic is to reverse and make the even position character to upper case using ternary operator.
 
String based program by imaginationhunt blogs
String based program


Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code the program.

Practical Implementation:

using System;

namespace patternProblem.String
{
    class String16
    {
        /*Second way*/
        public static void Main()
        {
            string str = string.Empty;
            string revStr = string.Empty;
            Console.Write("Enter String: ");
            str = Console.ReadLine();

            for (int i = str.Length - 1; i > 0; i--)
            {
                revStr = (i % 2 == 0) ? revStr + Char.ToUpper(str[i]) : revStr + str[i];
            }

            Console.WriteLine("Reverse String: {0}", revStr);
        }
    }
}

Output:
Based on the input, program will first reverse the string and then make the even position character to upper case. The output is shown below:

Enter String: imagination
Reverse String: noitanigami
Reverse String: NoItAnIgAm
Press any key to continue . . .


For any query, comment us below.

Skip to Main Table String based program

Previous - String based program #15

Next – Main Table Simple Program

Click imagination hunt to read latest blogs.


Keep learning and sharing...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...