14,693,352 members
See more:
Find the sum of n digit pallindromic numbers which are divisible by 8 and contains no zero in their decimal representation.

What I have tried:

```import java.util.*;

class GFG
{

static boolean isPalindrome(String s)
{
int left = 0, right = s.length() - 1;
while (left <= right)
{
if (s.charAt(left) != s.charAt(right))
{
return false;
}
left++;
right--;
}
return true;
}

static long getSum(int n)
{

int start = (int) Math.pow(10, n - 1);
int end = (int) (Math.pow(10, n) - 1);

long sum = 0;

for (int i = start; i <= end; i++)
{
String s = String.valueOf(i);

// Append
if (isPalindrome(s))
{
sum += i;
}
}

return sum;
}

public static void main(String[] args)
{
int n = 1;
long ans = getSum(n);
System.out.print(ans);
}
}```
Posted
Updated 30-Mar-20 3:32am
v2
OriginalGriff 30-Mar-20 7:23am

And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

Solution 1

Hints:
• an integer `i` is divisible by `8` if `(i%8)!=0`
• you have the string representation of the number, it is not a daunting task to find there is a `'0'` character in such a string