/* Java Program That Checks whether A Given String Is A Palindrome Or Not */
// File Name: palindrome.java
import java.io.*;
class palindrome {
public static void main(String args[]) throws IOException {
int i,j,len;
String s;
DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter The String Tobe Verified: ");
s=in.readLine();
System.out.println("Inputed String Is: "+s);
len=s.length();
for(i=0,j=len-1;i<len/2;i++,j--) {
if(s.charAt(i)!=s.charAt(j))
break;
}
if(i==j) {
System.out.println(s+" Is A Palindrome String");
System.out.println("www.shashanktechnologies.blogspot.com");
}
else {
System.out.println(s+" Is Not A Palindrome string");
System.out.println("www.shashanktechnologies.blogspot.com");
}
}
}
Output:
Compilation: G:/shashank>javac palindrome.java
Interpretation: G:/shashank>java palindrome
No comments:
Post a Comment