To lower or to upper
Given a string which has at least two words separated by space, write a method that changes first word in the string to upper case, second to lower case and so on.
Expected input and output
ToLowerOrToUpper("this is it") → "THIS is IT"
using System;
namespace CSharpExercises.Exercises.Library_functions
{
class ToLowerOrToUpperTask
{
public static string ToLowerOrToUpper(string word)
{
string[] words = word.Split(' ');
for (int i = 0; i < words.Length; i++)
{
words[i] = i % 2 == 0 ? words[i].ToUpper() : words[i].ToLower();
}
return String.Join(" ", words);
}
public static void Main()
{
Console.WriteLine(ToLowerOrToUpper("aaa BBB ccc DDD")); // AAA bbb CCC ddd
Console.WriteLine(ToLowerOrToUpper("Etiam mollis lectus ac facilisis venenatis")); // ETIAM mollis LECTUS ac FACILISIS venenatis
Console.WriteLine(ToLowerOrToUpper("th1s 15 5amp13 53nt3nc3")); // TH1S 15 5AMP13 53nt3nc3
}
}
}