Logo

Programming-Idioms

  • Python
  • Java
int square(int a) { return a * a; }
import static java.lang.Math.pow;
int square(int a) { return (int) pow(a, 2); }
int square(int x){
  return x*x;
}
Function<Integer,Integer> squareFunction = x -> x * x;
interface F { int get(int a); }
F square = x -> x * x;
import java.math.BigInteger;
BigInteger square(BigInteger a) {
    return a.multiply(a);
}
def square(x):
    return x*x

You don't have to explicitly write the return type
square = lambda x: x * x
def square(x):
    return x**2

You can use power operator
function Square (X : Integer) return Integer is
begin
   return X * X;
end Square;

New implementation...
< >
programming-idioms.org