+ Start a Discussion
k3k3 

algebra formulas (a+b)2 =a2 + b2 + 2ab

HOW to get this equation result using APEX program and writing its class.

Example:  INPUT  a=1,b=2


out put should be= 9
Vatsal KothariVatsal Kothari
Hi Kiran,

There is no methods available for a raise to power b, so we can do with this below approach:

Integer a = 1;
Integer b = 2;
Integer c;
c = (a*a) + (b*b) + (2*a*b);

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
k3k3
Thank Q Vatsal i got it . 
David "w00t!" LiuDavid "w00t!" Liu
There's a POW function that you can use too!

Integer a = 1;
Integer b = 2;
Integer c = Math.pow(a, 2) + Math.pow(b, 2) + (2 * a * b);

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_math.htm#apex_System_Math_pow
Gaurav NirwalGaurav Nirwal
we can taken the third variable c which is equal to (a+b) whole square 
then the answer can be seen is c=9
c=(a*a)+(b*b)+(2*a*b)