write a program that prints all palindromic numbers
between 0-9999 into the screen.
Note :The code should be written in java language.
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
for(int i=0;i<1000;i++){
if(i>0){
if(palindrome (i)){
System.out.println(i);
}
}
else{
System.out.println(i);
}
}
}
public static boolean palindrome (int n){
int temp=n,sum=0;
while(n>0){
int r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum){
return true;
}
return false;
}
}
Get Answers For Free
Most questions answered within 1 hours.