Java program to check for a Palindrome number.Get an input number or string. Get the reverse of the input number or string Compare the two numbers and string same or Not same.
The if statement is Java's conditional branch statement. It can be used to route program execution through two different paths. The if statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true. The if statement is written with the if keyword, followed by a condition in parentheses, with the code to be executed in between curly brackets.
The below program checks for a Palindrome number using a loop. A for loop is a repetition control structure which allows us to write a loop that is executed a specific number of times. The loop enables us to perform n number of steps together in one line. In for loop, a loop variable is used to control the loop.
import java.util.Scanner; public class number_palindrome { public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print("Enter The Number : "); int n = in.nextInt(); int temp=n; int reverse=0, rem; while(n!=0) { rem=n%10; reverse=reverse*10+rem; n/=10; } if(temp==reverse) { System.out.println(reverse+" Number is Palindrome"); }else { System.out.println(reverse+" Number is Not a Palindrome"); } } }
Enter The Number : 64546 64546 Number is Palindrome
Enter The Number : 4654 4564 Number is Not a PalindromeTo download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions