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.
ShowAll Questionssorted byDate Posted
Naveen Naidu 21

# How to write a apex class to find even and odd numbers ?

a sangeetha 5
Hi Naveen,

Hope this link give solution. I havn't tried yet.

http://salesforcehelps.blogspot.com/2016/09/odd-even-number-in-salesforce.html

Thanks
Ajay K Dubedi
Hi Naveen,

You can use the below code:

I have created an apex class as per your requirement.

```public class EvenAndOdd {

public static void findOddAndEvenNumber(Integer x){
Integer y = x/2;
System.debug('Number'+y);
Integer z = y * 2;
if(x == z ){
System.debug('The number is even.');
}else{
System.debug('The number is odd.');
}
}
}```

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Deepali Kulshrestha
Hi Naveen,

Please see the given below code and link with the help of this, you can solve your problem, it may be helpful to you.
```public class EvenAndOddApex {
public static void findOddAndEvenNumber(Integer num){
Integer num1 = num/2;
System.debug('Number>>>>'+num1);
Integer result = num1 * 2;
if(num == result ){
System.debug("The given number is even.");
}else{
System.debug("The given number is odd.");
}
}
}```

For another example you can follow the below link as well:
Link: https://webkul.com/blog/apex-programming-basics/

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com