function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nishant Kumar 274Nishant 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
CharuDuttCharuDutt
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>();
        lstnum.addAll(setnum);
            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]);
                }
            }
    }
}
Please Mark It As Best Answer If It Helps
Thank You! 

All Answers

CharuDuttCharuDutt
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>();
        lstnum.addAll(setnum);
            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]);
                }
            }
    }
}
Please Mark It As Best Answer If It Helps
Thank You! 
This was selected as the best answer
Nishant Kumar 274Nishant Kumar 274
Thanks CharuDutt. Can u please provide solution in anonymous window of apex class