Question:
Write a program to check if the sum of digits of a given number is palindrome number or not.
Input:
The first line of the input contains T denoting the number of testcases.Then each of the T lines contains single positive integer N denoting the value of number.
Output:
Output "YES" if pallindrome else "NO". (without the quotes)
Constraints:
Output:
Output "YES" if pallindrome else "NO". (without the quotes)
Constraints:
1<=T<=200
1<=N<=1000
Example:
1<=N<=1000
Example:
Input:
2
56
98
2
56
98
Output:
YES
NO
YES
NO
Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG {
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
int m = sc.nextInt();
for(int mi=0;mi<m;mi++){
int n = sc.nextInt();
int sum=0;
while(n!=0 ){
sum+=n%10;
n=n/10;
}
if(sum<10){
System.out.println("YES");
}
else{
System.out.println((sum%11!=0)?"NO":"YES");
}
}
}
}
Explanation: Here the sum which is palindromic number is divisible by 11. You can check it with any sum which is a palindromic number you want to. A good observant would have seen this. Another Beauty of Mathematics
Execution Time:0.1
Comments
Post a Comment