Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
Nishant Kumar 274

Write a program that reads a set of integers, and then prints the sum of the even and odd integers.

Write a program that reads a set of integers, and then prints the sum of the even and odd integers.
Best Answer chosen by Nishant Kumar 274
CharuDutt
Hii Nishant
Try Below Code
```public class evenodd {
public static void unitTest(){
set<Integer>setnum = new set<Integer>{0,1,2,3,4,5,6,7,8,9};
list<integer> lstnum = new list<integer>();
for(integer i=0;i<lstnum.size();i++){
if(math.mod(lstnum[i], 2) == 0){
system.debug('this is even: ' + lstnum[i]);
}else{
system.debug('this is odd: ' + lstnum[i]);
}
}
}
}```
Thank You!

CharuDutt
Hii Nishant
Try Below Code
```public class evenodd {
public static void unitTest(){
set<Integer>setnum = new set<Integer>{0,1,2,3,4,5,6,7,8,9};
list<integer> lstnum = new list<integer>();
for(integer i=0;i<lstnum.size();i++){
if(math.mod(lstnum[i], 2) == 0){
system.debug('this is even: ' + lstnum[i]);
}else{
system.debug('this is odd: ' + lstnum[i]);
}
}
}
}```