+ 1
Snap, Crackle and Pop
int[] numbers = new int[6]; int count = 0; while (count < 6) { numbers[count] = Convert.ToInt32(Console.ReadLine()); count++; } foreach (int i in numbers) { if (i % 3 == 0) { Console.Write("Pop" + " "); } else if (i % 3 != 0 && i % 2 != 0) { Console.Write("Snap" + " "); } else if (i % 3 != 0 && i % 2 == 0) { Console.Write("Crackle" + " "); } }
4 ответов
+ 4
Роман Жигунов ,
first of all, please post complete codes in future - thanks.
the issue is, that the code prints strings + a space. this is necessary for all outputs, except the last one.
what you can do is to collect all outputs in a string variable. it will also have the unnecessary last space. but this can be solved during the output like:
Console.WriteLine(output.Trim());
Trim() removes leading and trailing spaces.
happy coding!
+ 4
Роман Жигунов ,
see the file with a sample and my comments:
https://code.sololearn.com/cNuh3Lgd8tWV/?ref=app
+ 1
in the conditions of the problem, it is required to output sounds in one line, separated by a space,
did not understand your explanation, show an example
+ 1
aaaa) I understand now, thanks)