Here are the Mumbai University First Year Engineering sem-2 Computer programing 2 (CP-2) programs.These are tried and tested and work just fine.Njoy!
Please refer this to all your pals on all your social networks..thank you !
The grey color is only for the background it should cause no problems.
-------------------------------------------------------------------------------------------------------------
/*Program to check if a word(string) is palindrome or not
INPUT:liril then Output would be : Palindrome: liril */
import java.io.*;
class Palin {
public static void main(String args[]) throws java.io.IOException
{
DataInputStream buf = new DataInputStream(System.in);
System.out.print("Enter a string: ");
String str = buf.readLine();
char x[] = str.toCharArray();
int i;
int j;
for (i = 0; i <= x.length/2; i++)
{
if (x[i] != x[x.length - 1 - i])
{
i = -1;
break;
}
}
if (i == -1)
System.out.println("Not a palindrome: " + str);
else
System.out.println("Palindrome: " + str);
}
}
/*Palindrom means a word which spells the same both frontwards and backwards
eg:malayalam
eg:liril
eg:mcbgbbgbcn
*/
search
Sunday, June 13, 2010
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment