Computer Science, asked by anuragrastogi6165, 10 months ago

How to print the palindrome series using while loop in java

Answers

Answered by heroboy53
1

Answer:

In this method while loop repeats r=num%10; sum=(sum*10)+r; num/=10; these steps until num!=0 is false. If num=0 then it returns the sum, then compare the original number with this reverse number, if both are equal then it prints given number is a palindrome.

Answered by tamaghnadey1916
0

Answer:

import java.util.*;

class palindrome

{

public static void main()

{

Scanner sc=new Scanner(System.in);

int n,i,p,rev;

System.out.println("Enter a range for your loop");

n=sc.nextInt();

for(i=1;i<=n;i++)

{

rev=0;

p=i;

while (p>0)

{

rev=rev*10+(p%10);

p/=10;

}

if(i==rev)

System.out.print(i+" ");

}}}

Explanation:

I hope the code helps you

Similar questions