Answer the question
In order to leave comments, you need to log in
How to improve the vowel skipping algorithm?
There is a certain task. You want to create a character array of ten elements and assign the consonants of the English alphabet to it in order. I wrote it, but I think the execution is just terrible. How would you say? How can you rewrite the algorithm so that it doesn't look stupid?
using System;
public class NumberFour
{
static void Main()
{
int size = 10;
char[] symbs = new char[size];
char s = 'A';
Console.WriteLine("Массив сортировки согласных: ");
for (int i = 0; i < symbs.Length; i++)
{
symbs[i] = s;
s++;
if (symbs[i] == 'A' | symbs[i] == 'E' | symbs[i] == 'I')
{
symbs[i] = s++;
}
Console.Write("{0,3}", symbs[i]);
}
Console.WriteLine();
}
}
Answer the question
In order to leave comments, you need to log in
using System;
using System.Linq;
public class Program
{
private static char[] Filter = new [] { 'A', 'E', 'I', 'O' ,'U', 'Y' };
public static void Main()
{
var data = new char[10];
var s = 'A';
for(var i = 0; i < data.Length; s++)
if(!Filter.Contains(s))
data[i++] = s;
Console.WriteLine(string.Join(", ", data));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question