##Algorithm
Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
int max = Integer.MIN_VALUE;
for (int i = 999; i > 100 && i * 999 > max; i--) {
for (int j = 999; j > i; j--) {
....
- start high (999 x 999)
- Work backwards from there where the second number is larger than the first
- track your maximum
- terminate the loops if the current
i
(or smaller) values will never beat the maximum.
Using the above logic, you will eliminate a huge number of loops.
##Length check & Finding digit
Length check & Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the "finding digit"
##Palindrome
Palindrome
I like the following method for identifying palindromic numbers:
private static final int reverse(int value) {
int result = 0;
while (value != 0) {
result *= 10;
result += value % 10;
value /= 10;
}
return result;
}
Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);
##Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
int max = Integer.MIN_VALUE;
for (int i = 999; i > 100 && i * 999 > max; i--) {
for (int j = 999; j > i; j--) {
....
- start high (999 x 999)
- Work backwards from there where the second number is larger than the first
- track your maximum
- terminate the loops if the current
i
(or smaller) values will never beat the maximum.
Using the above logic, you will eliminate a huge number of loops.
##Length check & Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the "finding digit"
##Palindrome
I like the following method for identifying palindromic numbers:
private static final int reverse(int value) {
int result = 0;
while (value != 0) {
result *= 10;
result += value % 10;
value /= 10;
}
return result;
}
Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);
Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
int max = Integer.MIN_VALUE;
for (int i = 999; i > 100 && i * 999 > max; i--) {
for (int j = 999; j > i; j--) {
....
- start high (999 x 999)
- Work backwards from there where the second number is larger than the first
- track your maximum
- terminate the loops if the current
i
(or smaller) values will never beat the maximum.
Using the above logic, you will eliminate a huge number of loops.
Length check & Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the "finding digit"
Palindrome
I like the following method for identifying palindromic numbers:
private static final int reverse(int value) {
int result = 0;
while (value != 0) {
result *= 10;
result += value % 10;
value /= 10;
}
return result;
}
Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);
##Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
int max = Integer.MIN_VALUE;
for (int i = 999; i > 100 && i * 999 > max; i--}) ({
for (int j = 1000;999; j > i; j--) {
....
- start high (999 x 999)
- Work backwards from there where the second number is larger than the first
- track your maximum
- terminate the loops if the current
i
(or smaller) values will never beat the maximum.
Using the above logic, you will eliminate a huge number of loops.
##Length check & Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the "finding digit"
##Palindrome
I like the following method for identifying palindromic numbers:
private static final int reverse(int value) {
int result = 0;
while (value != 0) {
result *= 10;
result += value % 10;
value /= 10;
}
return result;
}
Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);
##Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
int max = Integer.MIN_VALUE;
for (int i = 999; i > 100 && i * 999 > max; i--} (
for (int j = 1000; j > i; j--) {
....
- start high (999 x 999)
- Work backwards from there where the second number is larger than the first
- track your maximum
- terminate the loops if the current
i
(or smaller) values will never beat the maximum.
Using the above logic, you will eliminate a huge number of loops.
##Length check & Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the "finding digit"
##Palindrome
I like the following method for identifying palindromic numbers:
private static final int reverse(int value) {
int result = 0;
while (value != 0) {
result *= 10;
result += value % 10;
value /= 10;
}
return result;
}
Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);
##Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
int max = Integer.MIN_VALUE;
for (int i = 999; i > 100 && i * 999 > max; i--) {
for (int j = 999; j > i; j--) {
....
- start high (999 x 999)
- Work backwards from there where the second number is larger than the first
- track your maximum
- terminate the loops if the current
i
(or smaller) values will never beat the maximum.
Using the above logic, you will eliminate a huge number of loops.
##Length check & Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the "finding digit"
##Palindrome
I like the following method for identifying palindromic numbers:
private static final int reverse(int value) {
int result = 0;
while (value != 0) {
result *= 10;
result += value % 10;
value /= 10;
}
return result;
}
Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);
##Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
int max = Integer.MIN_VALUE;
for (int i = 999; i > 100 && i * 999 > max; i--} (
for (int j = 1000; j > i; j--) {
....
- start high (999 x 999)
- Work backwards from there where the second number is larger than the first
- track your maximum
- terminate the loops if the current
i
(or smaller) values will never beat the maximum.
Using the above logic, you will eliminate a huge number of loops.
##Length check & Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the "finding digit"
##Palindrome
I like the following method for identifying planindromespalindromic numbers:
private static final int reverse(int value) {
int result = 0;
while (value != 0) {
result *= 10;
result += value % 10;
value /= 10;
}
return result;
}
Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);
##Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
int max = Integer.MIN_VALUE;
for (int i = 999; i > 100 && i * 999 > max; i--} (
for (int j = 1000; j > i; j--) {
....
- start high (999 x 999)
- Work backwards from there where the second number is larger than the first
- track your maximum
- terminate the loops if the current
i
(or smaller) values will never beat the maximum.
Using the above logic, you will eliminate a huge number of loops.
##Length check & Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the "finding digit"
##Palindrome
I like the following method for identifying planindromes:
private static final int reverse(int value) {
int result = 0;
while (value != 0) {
result *= 10;
result += value % 10;
value /= 10;
}
return result;
}
Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);
##Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
int max = Integer.MIN_VALUE;
for (int i = 999; i > 100 && i * 999 > max; i--} (
for (int j = 1000; j > i; j--) {
....
- start high (999 x 999)
- Work backwards from there where the second number is larger than the first
- track your maximum
- terminate the loops if the current
i
(or smaller) values will never beat the maximum.
Using the above logic, you will eliminate a huge number of loops.
##Length check & Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the "finding digit"
##Palindrome
I like the following method for identifying palindromic numbers:
private static final int reverse(int value) {
int result = 0;
while (value != 0) {
result *= 10;
result += value % 10;
value /= 10;
}
return result;
}
Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);