A
Ahmed Moustafa
Hello,
What would be the most efficient to write a maximum function in Java?
Initially, I had the comparisons that looked for the maximum inside the
main method and then moved it inside its own method (code is below) to
be called from within the main method (to make the code look prettier),
but that cost me almost 3 additional seconds processing time:
<code>
private static float maximum (float a, float b, float c, float d) {
float t1 = a > b ? a : b;
float t2 = c > d ? c : d;
return t1 > t2 ? t1 : t2;
}
</code>
Is there something like C's macros to keep the code clean but to save
the processing time for calling the macro?
Thanks in advance,
Ahmed
What would be the most efficient to write a maximum function in Java?
Initially, I had the comparisons that looked for the maximum inside the
main method and then moved it inside its own method (code is below) to
be called from within the main method (to make the code look prettier),
but that cost me almost 3 additional seconds processing time:
<code>
private static float maximum (float a, float b, float c, float d) {
float t1 = a > b ? a : b;
float t2 = c > d ? c : d;
return t1 > t2 ? t1 : t2;
}
</code>
Is there something like C's macros to keep the code clean but to save
the processing time for calling the macro?
Thanks in advance,
Ahmed