java program for checking palindrome number

java program for checking 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 " );
}
}
}