Информатика, вопрос задал pisarenkobogdan00 , 1 год назад

Давно 2 списка.
List = [11,20,31,40,51]
List2 = [60,71,80,91,100]
Знайти всі парні елементи із списку List і перемістити в список List2
Знайти всі непарні елементи із списку List2 і перемістити в список List1

Результат
List = [11,31,51,71,91]
List2 =[20,40,60,80,100]
Язык Dart плз

Ответы на вопрос

Ответил evgeniabelik98
2

Ответ:

Объяснение:

// Define two lists

List<int> list = [11, 20, 31, 40, 51];

List<int> list2 = [60, 71, 80, 91, 100];

// Loop through the first list and find even elements

for (int i = 0; i < list.length; i++) {

 // Check if the element is even using isEven property

 if (list[i].isEven) {

   // Add the element to the second list using add() method

   list2.add(list[i]);

   // Remove the element from the first list using removeAt() method

   list.removeAt(i);

   // Decrement i to avoid skipping elements

   i--;

 }

}

// Loop through the second list and find odd elements

for (int j = 0; j < list2.length; j++) {

 // Check if the element is odd using isOdd property

 if (list2[j].isOdd) {

   // Add the element to the first list using add() method

   list.add(list2[j]);

   // Remove the element from the second list using removeAt() method

   list2.removeAt(j);

   // Decrement j to avoid skipping elements

   j--;

 }

}

// Print the final lists

print(list); // [11,31,51,71,91]

print(list2); // [20,40,60,80,100]

Новые вопросы