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
SimrinSimrin 

modulas operand in apex

Hello,

How can i achieve Module operand in Visualforce.

NUMBER % 2 == 0  //even
NUMBER % 2 == 1 //odd
Best Answer chosen by Simrin
shiva pendemshiva pendem
HI Simrin,

Try this Link 
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008yLvIAI


Thanks
Shiva.

All Answers

SimrinSimrin
i am incrementing a integer varialble, I want to check if the numbr is even or odd
shiva pendemshiva pendem
HI Simrin,

Try this Link 
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008yLvIAI


Thanks
Shiva.
This was selected as the best answer
SIVASASNKARSIVASASNKAR
Hi Simrin,

You can try this code:
Integer incrementer = 0;
String evenOROdd = '';
for(integer i=0;i<50;i++){
    
   evenOROdd = ((Math.MOD(incrementer,2) == 0 ) ? 'Even' : 'ODD');
   System.debug(i+'  = ' +evenOROdd );
   incrementer++;

}

Output:
0 = Even
1 = ODD
2 = Even
3 = ODD
4 = Even
.
.
.

Thanks,
Sivasankar