beingtopper.jkp@gmail.com
+91-8700702530
Free Demo

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
B.tech notesBasic ProgramsBCA NOTESInformation technologyJava ProgramsPrograms/Algorithm

java program for checking palindrome number

Being Topper 18/02/2014 0 Comments

Palindrome Program in Java

In this program, you’ll learn to check whether a number is palindrome or not in Java. This is done by using for and while loop.

Java-program-for-checking-palindrome-number

Palindrome number in java:

A palindrome number is a number that is same after reverse. For example 141, 757, 38583, 747, 171, 52925 are the palindrome numbers. It can also be a string like LOL, NITIN etc.

 

Palindrome number algorithm

  • Get the number to check for palindrome
  • Hold the number in temporary variable
  • Reverse the number
  • Compare the temporary number with reversed number
  • If both numbers are same, print “palindrome number”
  • Else print “not palindrome number”

 

Java program for checking palindrome number :

 

import java.io.* ;
import java.util.Scanner;
class CheckPalindrome
{
public static void main (String s[] )
{

Scanner console = new Scanner(System.in);
int number ;

System.out.println( " Enter the array size " );
int size = console.nextInt();

int array[] = new int[size];
for ( int i=0; i<size;i++)
{
System.out.println ( "Enter the number : array["+i+"]");
number = console.nextInt() ;

array[i] = number ;
}

int c = array.length-1 ;
for ( int i = 0; i < array.length ; i++)
{
if ( array[i] == array[c])
{
c--;
}
}

if (c == (-1) )
{
System.out.println ( " this array is a palindrome ");
}
else
{System.out.println( " this is not a palindrome " );
}
System.out.println( " this is the second method to solve palindrome " );

int flag1 = 1;
for(int i = 0, k = array.length-1; i<array.length&k>(-1);i++,k--)
{
if ( array[i] != array[k])
{
System.out.println ("this is not a palindrome");
flag1 = 0; break ;
}

}
if (flag1==1){
System.out.println( " this is a palindrome " );
}
}
}

 

java program for checking palindrome number
AboutBeing Topper
In Socials:
Prevjava program for checking even and odd number18/02/2014
java program for checking prime number18/02/2014Next

Related Posts

Gmail

HOW TO CREATE A GMAIL ACCOUNT?

If you are coming on this article, I hope you are looking for create an gmail account,...

Being Topper 18/06/2017
Gmail

How we Can Change Gmail Account Password?

If you are coming to this article, I hope you are looking to know about changing a...

Being Topper 11/07/2017
Categories
Recent Posts
  • Best Email Marketing Software and Services
  • How to Apply Adsense on YouTube
  • Complete Guide to Writing a Newsletter !
  • Benefits of Creating Email List for small Businesses | Digital Marketing
  • Create Account or Get Email Alerts When New Employees Join a Company

Copyright © 2021 Being Topper ® . All Rights Reserved