Simplify Lesson 1 Task 3

This commit is contained in:
Stanislav Mykhailenko 2023-03-19 00:08:23 +02:00
parent fe6c5d5dbf
commit 584fd2c0d8
GPG key ID: 1E95E66A9C9D6A36

View file

@ -6,7 +6,6 @@
int duplicate; int duplicate;
List<int> numbers = new List<int>(); List<int> numbers = new List<int>();
string? userInput;
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
@ -14,9 +13,8 @@ for (int i = 0; i < 10; i++)
do do
{ {
Console.Write(string.Format("Enter number {0}: ", i + 1)); Console.Write($"Enter number {i + 1}: ");
userInput = Console.ReadLine(); } while (!int.TryParse(Console.ReadLine(), out newNumber));
} while (!int.TryParse(userInput, out newNumber));
numbers.Add(newNumber); numbers.Add(newNumber);
} }
@ -24,8 +22,7 @@ for (int i = 0; i < 10; i++)
do do
{ {
Console.Write("Enter a number to duplicate: "); Console.Write("Enter a number to duplicate: ");
userInput = Console.ReadLine(); } while (!int.TryParse(Console.ReadLine(), out duplicate));
} while (!int.TryParse(userInput, out duplicate));
for (int i = 0; i < numbers.Count; i++) { for (int i = 0; i < numbers.Count; i++) {
if (numbers[i] == duplicate) if (numbers[i] == duplicate)
@ -35,8 +32,4 @@ for (int i = 0; i < numbers.Count; i++) {
} }
} }
Console.WriteLine( Console.WriteLine(String.Join(", ", numbers));
string.Join(", ",
numbers.Select(number => number.ToString())
)
);