Skip to main content

How to write a palindrome program in java

The Below program will tell you the given number is palindrome or not. In generally most of the interviewers are asking this question during interview process and candidates struggling to answer this question. Please practice the below program, this will help you. I hope.

package testing;
import java.util.Scanner;
/**
 * Please find the Java program to check if given number is palindrome or not.
 * If number and its reverse is equal then this is called palindrome
 * This program can also be used to reverse a number in Java
 */
public class Palindromeprogram {

    public static void main(String args[]){
     
        System.out.println("Please Enter a number : ");
        int palindrome = new Scanner(System.in).nextInt();
     
        if(isPalindrome(palindrome)){
            System.out.println("Number : " + palindrome + " is a palindrome");
        }else{
            System.out.println("Number : " + palindrome + " is not a palindrome");
        }      
    }
    /*
     * Here Java method to check if given number is palindrome or not
     */
    public static boolean isPalindrome(int number) {
        int palindrome = number; // copied number into variable
        int reverse = 0;
        while (palindrome != 0) {
            int remainder = palindrome % 10;
            reverse = reverse * 10 + remainder;
            palindrome = palindrome / 10;
        }
        if (number == reverse) {
            return true;
        }
        return false;
    }

}

Output:
Please Enter a number :
2345
Number : 2345 is not a palindrome
Please Enter a number :
21012
Number : 21012 is a palindrome

Popular posts from this blog

List of software companies in Chennai

List of software companies in Chennai India's Information technology is an industry consisting of IT services and business process outsourcing(BPO). In india information technology is playing an important role, IT sector in India is generating more than 3 million employment. IT & ITeS industry in India has grown enormously. Indian Information Technology has made a mark in the world. Many MNC's are started branches in Indian cities like Bangalore, Chennai, Delhi etc,. The below table shows you list of software companies in Chennai. 4i Apps Solutions Pvt Ltd http://www.4iapps.com Abra Technologies http://www.abratechnologies.com Accel Frontline Ltd http://www.accelfrontline.in Adrenalin eSystems Ltd http://www.myadrenalin.com Akmin Technologies Pvt Ltd http://www.akmin.com American Megatrends India Pvt Ltd http://www.amiindia.co.in Anantara Solutions Pvt Ltd http://www.anantsol.com Arrowpoint Technologies Pvt Ltd http://www.arrowpointtechn...

z/890 SHUT DOWN Procedure in Mainframe Systems

Issue the following commands one by one from the master console. 1. P TCPIP 2. C CICS1 3. -Stop DB2 4. P TSO 5. Z NET 6. F BPXOINIT, SHUTDOWN = FORKINIT 7. C LLA - Library look aside facility 8. C VLF - Virtual look aside facility 9. F DLF, MODE = DRAIN - Data look aside facility. 10. P DLF 11. P RMF 12. P FFST - First Failure Support Technology. 13. %STOP - Racf 14. C SYSLOGD1 15. $P INIT - Initiators 16. $P JES2, TERM 17. Z EOD 18. Close the consoles 19. Double click on groups cpc images. The list of images present is displayed. 20. Single Click on the image then Double Click on the Deactivate button which is at the Daily panel and Confirm by clicking OK on the pop up window.

Freshers Openings at EMC as Systems Engineer On Dec 2014

Company      EMC Corporation Website       www.emc.com Eligibility      BE/B.Tech/M.Tech/MCA Experience    Freshers Location        Bangalore Job Role       Systems Engineer JOB SUMMARY: Company profile : EMC provides the technologies and tools that can help you release the power of your information. We can help you design, build, and manage flexible, scalable, and secure information infrastructures. And with these infrastructures, you'll be able to intelligently and efficiently store, protect, and manage your information so that it can be made accessible, searchable, shareable, and, ultimately, actionable. Job Description: Candidate Profile: 1. Candidate should possess B.Tech/M.Tech/MCA degree from a recognised university. 2. Should have good Time management skills, Organizational skills, Cross-Functional skills. 3. Excellent Communication skills. 4. Ability to in...