Write a program in Java to display the largest four-digit even palindromic number.
Answers
Answered by
1
Answer:
public class Main
{
public static void main(String[] args) {
for(int i=1;i<=10000;i++)
{
int rev=palindrome(i);
if(rev==i)
{ if(rev%2==0)
{
System.out.print(i+",");
}
}
}
}
public static int palindrome(int n)
{ int rev=0;
while(n>0)
{
int r=n%10;
n=n/10;
rev=(rev*10)+r;
}
return rev;
}
}
Explanation:
last number in the output is largest 4 digit even palindrome
Attachments:
Similar questions