0

I need to print a sentence in which all the words will be written out in alphabetical order

For example, user will enter sentence: "I Dream about good Times". At the end it should be :"about Dream good I Times"(not "DreAm I Times about good"). problem is what should i do with uppercase and lowercase. Right now it looks like this and does what i written in bracket string line = Console.ReadLine(); string[] array = line.Split(' '); for (int k = 0; k < array.Length; k++) { for (int i = 0; i < array.Length - 1; i++) { if (array[i][0] > array[i + 1][0]) { string temp = array[i]; array[i] = array[i + 1]; array[i + 1] = temp; } } } string result = ""; for (int f = 0; f < array.Length; f++) { result += array[f] + " "; } Console.WriteLine(result);

7th Nov 2019, 9:28 PM
Ksenia Dmitrieva
Ksenia Dmitrieva - avatar
1 Respuesta
+ 2
You could do it easier with Linq https://code.sololearn.com/cUX7i97GRDdd/?ref=app
7th Nov 2019, 11:51 PM
Jakub Stasiak
Jakub Stasiak - avatar