Find palindrome number program in java using for loop
The word “palindrome” has a Greek origin, a word, number, or set of characters that reads the same forward and backwards. Some examples of a palindrome are MALAYALAM, 343, 2001002, etc. Palindrome in Java can be implemented using many ways. Here we will discuss some important ways:
- Using while loops
- Using for loops
- Using recursion
What is a Palindrome Number?
A Palindrome no. is the number that remains the same when its digits get reversed.
Ex: 15451, for example: If we take 131 and reverse it then after reversing the number remains the same.
Steps to Palindrome Number program
- Input the number from the user.
- Then Reverse it.
- Compare the number with the number entered by the user.
- If both the no.’s are the same then print the number as a palindrome
- Else print not a palindrome.
Finding Palindrome number Using while loop
Finding Palindrome number Using for loop
1) The number is called a palindrome if a number is equal to reverse of its number.
2) For loop repeats rem=num%10; s=(s*10)+rem these steps until num>0. If the condition is false, then it compares the s value with t, if both are equal then it prints the given number is a palindrome.
Finding Palindrome number Using Using Recursion
1) Using the “Palin” object p, we will call the palindromeOrNot(a) method.
2) The method palindromeOrNot(int num) calls itself as palindromeOrNot(num) until num!=0, if num=0 then it returns sum and sum assigned to s and compares with t, if both are equal then it prints message as “palindrome number”.
Find palindrome number program in java using for loop – Find palindrome number program in java using for loop – Find palindrome number program in java using for loop – Find palindrome number program in java using for loop