Java Reference
In-Depth Information
// which cannot both be running at the same time.
/* Statically allocated array to avoid new-ing each time. */
static
static long
long [] digits = new
new long
long [ MAX_DIGITS ];
/** Check if a number is palindromic. */
static
static boolean
long num ) {
// Consider any single digit to be as palindromic as can be
iif ( num >= 0 && num <= 9 )
return
boolean isPalindrome ( long
return true
true ;
int
int nDigits = 0 ;
while
while ( num > 0 ) {
digits [ nDigits ++] = num % 10 ;
num /= 10 ;
}
for
for ( int
int i = 0 ; i < nDigits / 2 ; i ++)
iif ( digits [ i ] != digits [ nDigits - i - 1 ])
return
return false
false ;
return
return true
true ;
}
static
static long
long reverseNumber ( long
long num ) {
int
int nDigits = 0 ;
while
while ( num > 0 ) {
digits [ nDigits ++] = num % 10 ;
num /= 10 ;
}
long
long ret = 0 ;
for
for ( int
int i = 0 ; i < nDigits ; i ++) {
ret *= 10 ;
ret += digits [ i ];
}
return
return ret ;
}
}
See Also
People using Java in scientific or large-scale numeric computing may wish to check out the
historical archive of the Java Grande Forum , which was once a working group aiming to en-
sure Java's usability in these realms.
Search WWH ::




Custom Search