Update Lesson 1 Task 3
This commit is contained in:
parent
62266346ac
commit
49969a1b5f
1 changed files with 18 additions and 14 deletions
|
@ -9,27 +9,31 @@ List<int> numbers = new List<int>();
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
int newNumber;
|
int newNumber;
|
||||||
|
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
Console.Write($"Enter number {i + 1}: ");
|
Console.Write($"Enter number {i + 1}: ");
|
||||||
} while (!int.TryParse(Console.ReadLine(), out newNumber));
|
if (int.TryParse(Console.ReadLine(), out newNumber))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
numbers.Add(newNumber);
|
numbers.Add(newNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
Console.Write("Enter a number to duplicate: ");
|
Console.Write($"Enter number to duplicate: ");
|
||||||
} while (!int.TryParse(Console.ReadLine(), out duplicate));
|
if (int.TryParse(Console.ReadLine(), out duplicate))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < numbers.Count; i++) {
|
for (int i = 0; i < numbers.Count; i++) {
|
||||||
if (numbers[i] == duplicate)
|
if (numbers[i] == duplicate)
|
||||||
{
|
{
|
||||||
numbers.Insert(i, duplicate);
|
numbers.Insert(i, duplicate);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine(String.Join(", ", numbers));
|
Console.WriteLine(String.Join(", ", numbers));
|
||||||
|
|
Reference in a new issue