February 12 2015

Palindrome number program in java

Palindrome number program in java

A palindromic number is a number that remains the same when its digits are reversed.Like 13231 for example is palindrome number whereas 2344 is not.

Algorithm

Step 1: Take the number from user and store entered number in number and tempNumber

Step 2: Repeat steps 3-5 until number != 0

Step 3: Divide number by 10 and determine remainder

reminder = number % 10;

Setp 4: Calculate reverseNumber

              reverseNumber = reverseNumber * 10 + reminder;

Step 5: Divide number by 10

             number= number/ 10;

Step 6: Compare the reverseNumber with tempNumber

Step 7: If both are equal it is a palindrome number.

Step 8: Else It is not a palindrome number.

Step 9: Print the result

Palindrome number program in java


package com.answersz.impprograms;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class PalindromeNumberProgram {

public static void main(String[] args) throws NumberFormatException,

IOException {

System.out.print("Enter number to check Palindrome Number or not : ");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int number = Integer.parseInt(br.readLine());

int tempNumber = number;

int reverseNumber = 0, reminder;

while (number > 0) {

reminder = number % 10;

reverseNumber = reverseNumber * 10 + reminder;

number = number / 10;

}

if (reverseNumber == tempNumber)

System.out.println(tempNumber + " is a Palindrome Number");

else

System.out.println(tempNumber + " is not a Palindrome Number");

}

}

Output

Enter number to check Palindrome Number or not : 343

343 is a Palindrome Number

Enter number to check Palindrome Number or not : 114

114 is not a Palindrome Number

 


Copyright © 2014. All rights reserved.

Posted February 12, 2015 by answersz in category Bluej Java Programs for ICSE Class 10 and 9 Practice, Core Java

Leave a Comment

Your email address will not be published. Required fields are marked *

*