You need to sign in to do that
Don't have an account?

how to find that number is even/odd or prime number or armstrong or a palindrome.
Hi,
I am new to salesforce.pl anyone can help me how to implement trigger for the following
When a number is inserted, how to find that number is even/odd or prime number or armstrong or a palindrome.
Thanks in advance
Programming for these type of tasks is similar in all languages. The operators supported by Apex are availabler here -
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_expressions_operators_understanding.htm
As an example for even/odd, you could do the following. Lets say x is the original number.
y = x/2;
z = y * 2;
If(z == x) { System.Debug('Even'); }
else System.Debug('Odd');
As an example if x is 7, y will be set to 3 and z will be set to 6. As z will not be equal to x, Odd will be printed.
Welcome to Salesforce!!
To get familiar with the Apex programming language, start with the easy one --even/odd. Here is a link to the Apex Dev Guide (http://www.salesforce.com/us/developer/docs/apexcode/index.htm). Google will also be your best friend. Seach for 'salesforce apex <whatever>". And, of course, we are here to help you over the rough spots.
https://notepad.software/ https://vidmate.onl/download/ https://filezilla.software/
Please try this code:
For trigger replace 'num' with the field which you want to check or the number which you are inserting in the database.
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
Integer x = 10;
if(math.mod(x, 2) == 0){
system.debug('this is even number: ' + x);
}
else
{
system.debug('this is odd number: ' + x);
}
Few things i would like to add in pallindrome logic is that when you compare in if condition , it will throw error as we are comparing string and integer
//
String str1='';
String stringNum = String.valueOf(num);
str1 = stringNum.reverse();
if(str1==num)
System.debug('Number is pallindrome');
//
Corrected Logic
String str1='';
String stringNum = String.valueOf(num);
str1 = stringNum.reverse();
integer nnum = Integer.ValueOf( str1 );
if(nnum==num)
System.debug(num +'Number is pallindrome');
else
System.debug(num+'Number is not a pallindrome');
Thanks & Regards
Naman Negi