Computer Science, asked by aditichowdhary15, 3 months ago

class abc
{
void fun(int a)
{
int sum = 0;
while(a>0)
{
int rem = a%10;
int sum = sum + rem;
int a = a/10;
}
System.out.println("sum of digit is : " +sum);
System.out.println("end");
}
}


find the mistake in the program and its output
and please don't give wrong answer

Answers

Answered by ANGADOFFICIAL
2

Answer:

Input : 2332

Output : Yes it is Palindrome.

Explanation:

original number = 2332

reversed number = 2332

Both are same hence the number is palindrome.

Input :1111

Output :Yes it is Palindrome.

Input : 1234

Output : No not Palindrome.

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

A recursive solution is discussed in below post.

Check if a number is Palindrome

In this post a different solution is discussed.

1) We can compare the first digit and the last digit, then we repeat the process.

2) For the first digit, we need the order of the number. Say, 12321. Dividing this by 10000 would get us the leading 1. The trailing 1 can be retrieved by taking the mod with 10.

3 ) Now, to reduce this to 232.

(12321 % 10000)/10 = (2321)/10 = 232

4 ) And now, the 10000 would need to be reduced by a factor of 100.

Here is the implementation of the above algorithm :

Explanation:

this is the answer

Similar questions