Java Online Compiler
Example: Palindrome Number Program in Java using While loop
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Palindrome Number Program in Java using While loop import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter an integer number::\n"); int x = in.nextInt(), r, rN = 0, oN; // rN - To store the reverse number // oN - To store the original number // r - To store the remainder oN = x; // this reverse number will be stored during iteration while (x != 0) { r = x % 10; rN = rN * 10 + r; x /= 10; } // if the original number will match with reverse then palindrome case will be true if (oN == rN) { System.out.println ("This " + oN + " is a palindrome number."); } else { System.out.println ("This " + oN + " is not a palindrome number!"); } } }
90009
Output
Clear
ADVERTISEMENTS