Forum: Java Oct 13th, 2008 |
| Replies: 11 Views: 1,380 >Is there a better way?
Yes, design the class hierarchy such that you don't need to know the dynamic type of the object. Perhaps some form of strategy pattern would clean up that selection code. |
Forum: Java Oct 30th, 2004 |
| Replies: 4 Views: 8,691 Calculating the least common multiple is trivial if you have a routine to find the greatest common divisor:
public int lcm ( int a, int b )
{
return a * b / gcd ( a, b );
}
You shouldn't... |
Forum: Java Oct 29th, 2004 |
| Replies: 4 Views: 8,691 >I got the method down here (for the first integer):
Why not write it generally for all integers?
public int reverse_integer ( int val )
{
int ret = 0;
while ( val != 0 ) {
ret = 10... |