int mystery (float a, float b)
{
int value;
if (a < b)
value = -1;
elseif (a > b)
value = 1;
else
value = 0;
return value;
}
int mystery (float a, float b)
{
if (a < b)
return -1;
elseif (a > b)
return 1;
elsereturn 0;
}
char first(char a, char b)
{
if(a < b)
return a;
elsereturn b;
}
Returns the smaller parameter.
float second(float a, float b)
{
float answer;
if(a < b)
answer = a - b;
else
answer = b - a;
return answer;
}
Returns the negative difference of the parameters.
c) is invalid since println is a void method. It doesn't return anything to store in x.
d) is valid, but pointless since the value of f(x) is lost.
float largest(float a, float b, float c)
{
if (a > b && a > c)
return a;
elseif (b > c)
return b;
elsereturn c;
}
int gcd (int x, int y)
{
int divisor = 1, small = abs(x);
if (abs(y) < abs(x))
small = abs(y);
for (int i = 2; i <= small; i++)
if (x % i == 0 && y % i == 0)
divisor = i;
return divisor;
}