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
TUSHAR KHORGADETUSHAR KHORGADE 

want to print even n odd number with there counts pls help me i m stuck in below code

Create a map populate it with two records Odd and Even. Run a loop from 1-50, if you find an even number increase the count for an even named record in the map or else increase the count of odd named record. Odd and even are keys, counts are values. Example map syntax: Map<String,integer> CountNumber = new map<String,Inetger>({'Even':4},{'Odd':3});

my code is this

public class NumberTest {
    integer oddCount = 0;
    integer evenCount = 0;
    
    Map<string,integer> countNumber = new Map<string,integer>();
    
    for(int i=1;i<=50;i++)
    {
        if(a[i] % 2 != 0){
            countNumber.put('Odd',oddCount++);
        }
        else{
            countNumber.put('Even',evenCount++);
        }
    }
}
SFDC12SFDC12
Hi try below code,

public class Evennumber {
    public integer i;
    public void print(){
        integer total=0;
        for(i=1;i<=100;i++){
            if(math.mod(i,2)==0){
                total=total+i;
            }else{
             system.debug('this is odd number: ' + i);
                system.debug('total:'+i);
            }
        }
    }     
    }

Thanks,mark it as best answer if it helps.