Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class MethodForSortingStrings
- {
- /*You are given an array of strings.
- * Write a method that sorts the array by the length of its elements
- * (the number of characters composing them).*/
- static void Main()
- {
- string temp;
- string[] a = { "aaaaaaa", "nnnn", "ss", "iiiii", "ooo" };
- for (int i = 0; i < a.Length; i++)
- {
- for (int j = i; j < a.Length; j++)
- if (a[i].Length > a[j].Length)
- {
- temp = a[i];
- a[i] = a[j];
- a[j] = temp;
- }
- }
- for (int i = 0; i < a.Length; i++)
- {
- Console.WriteLine(a[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement