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.
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
Next – Main
Table Simple
Program
Keep learning and sharing...
No comments:
Post a Comment