"KEEP LEARNING, DON'T STOP."
"KEEP LEARNING, DON'T STOP."
In this section you will learn how to make palindrome number program in java. We will use while loop condition to perform palindrome number check operation.
A palindrome number is a number such that if you reverse it, it will not change. The number should be remain same. To check whether a number is palindrome or not first we reverse it and then compare the number obtained with the original, if both are same then number is palindrome otherwise not.
212, 121, 77077, 11611.
Scanner function is use to take the input from user in java.
import java.util.Scanner; class Palindrome { public static void main(String arg[]) { int n, reverse=0, temp; Scanner sc = new Scanner(System.in); System.out.println("ENTER A NUMBER:- "); n = sc.nextInt(); temp = n; while (temp != 0) { reverse = reverse * 10; reverse = reverse + temp % 10; temp = temp / 10; } if (n == reverse) { System.out.println("ENTER NUMBER IS PALINDROME."); } else { System.out.println("ENTER NUMBER IS NOT PALINDROME."); } } }
ENTER A NUMBER:- 121 ENTER NUMBER IS PALINDROME.
Advertisment