+ Start a Discussion

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.

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);

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