Advertisement
Hiteshw11

Given a list of integers, create two separate lists: one containing all even numbers and the other c

Nov 17th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.69 KB | Source Code | 0 0
  1. // Given a list of integers, create two separate lists: one containing all even numbers and the other containing all odd numbers.
  2.  
  3. void main(){
  4.   List<int> nums=[4,3,6,7,9,2,1];
  5.   print("The List of even numbers is ${evenNums(nums)}");
  6.   print("The List of odd numbers is ${oddNums(nums)}");
  7.  
  8.  
  9. }
  10.  
  11. List<int> evenNums(List<int> abc)
  12. {
  13.   List<int> evennos=[];
  14.   for(int i=0;i<abc.length;i++)
  15.   {
  16.     if(abc[i]%2==0)
  17.     {
  18.       evennos.add(abc[i]);
  19.      
  20.     }
  21.   }
  22.   return evennos;
  23. }
  24.  
  25. List<int> oddNums(List<int> def)
  26. {
  27.   List<int> oddnos=[];
  28.   for(int j=0;j<def.length;j++)
  29.   {
  30.     if(def[j]%2!=0)
  31.     {
  32.       oddnos.add(def[j]);
  33.      
  34.     }
  35.   }
  36.   return oddnos;
  37. }
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement