/*
Program to check whether a string is a palindrome or not.
*/
import java.io.*;
class palindrome
{
static String n;
static int l;
public static void main(String args[]) throws IOException
{
palindrome call = new palindrome();
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
// Read the String
System.out.print("Enter a String : ");
n = br.readLine();
l = n.length();
call.palindrome();
}
public void palindrome()
{
int f = -1;
for(int i=0;i<=l/2;i++)
{
if(n.charAt(i)!=n.charAt(l-1-i))
{
f=1;
break;
}
}
if(f==-1)
System.out.println("
" +n +" is a Palindrome");
else
System.out.println("
" +n +" is NOT a Palindrome");
}
}
/**
* ALGORITHM :
* ---------
* 1. Start
* 2. Accept a sentence from the user.
18* 3.
* 4.
* 5.
*
* 6.
* 7.
*/
Extract each character from the sentence.
Reverse the String.
IF the string remains unchanged THEN "String is a Palindrome".
else
"String is NOT a Palindrome".
End
/*
OUTPUT :
------
Enter a String : rotator
rotator is a Palindrome
*/
Program to check whether a string is a palindrome or not.
*/
import java.io.*;
class palindrome
{
static String n;
static int l;
public static void main(String args[]) throws IOException
{
palindrome call = new palindrome();
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
// Read the String
System.out.print("Enter a String : ");
n = br.readLine();
l = n.length();
call.palindrome();
}
public void palindrome()
{
int f = -1;
for(int i=0;i<=l/2;i++)
{
if(n.charAt(i)!=n.charAt(l-1-i))
{
f=1;
break;
}
}
if(f==-1)
System.out.println("
" +n +" is a Palindrome");
else
System.out.println("
" +n +" is NOT a Palindrome");
}
}
/**
* ALGORITHM :
* ---------
* 1. Start
* 2. Accept a sentence from the user.
18* 3.
* 4.
* 5.
*
* 6.
* 7.
*/
Extract each character from the sentence.
Reverse the String.
IF the string remains unchanged THEN "String is a Palindrome".
else
"String is NOT a Palindrome".
End
/*
OUTPUT :
------
Enter a String : rotator
rotator is a Palindrome
*/
0 komentar:
Posting Komentar