I want to see if anyone knows how to optimize the code below:
public class smallestTest
{
public static void main(String[] args)
{
double resultSmallest = smallest(2.5, 3.5, 4.5);
System.out.println("The smallest number out of 2.5, 3.5, and 4.5 is: " + resultSmallest);
}
/**
Computes the smallest of three variables
@param x, y, z
@returns smallestNumber
*/
public static double smallest(double x, double y, double z)
{
double smallestNumber = 0;
if ( x < y && x < z)
{
smallestNumber = x;
}
else if (y < x && y < z)
{
smallestNumber = y;
}
else if (z < x && z < y)
{
smallestNumber = z;
}
return smallestNumber;
}
}