import java.util.Scanner;
public class Palindromes
{
public static boolean isPalindrom(String s)
{
if(s.length() == 0 || s.length() == 1)
return true;
if(s.charAt(0) == s.charAt(s.length()-1))
return isPalindrom(s.substring(1, s.length()-1));
return false;
}
public static void main(String[]args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Input:");
String x = sc.nextLine();
if(isPalindrom(x))
System.out.println(x + " is a palindrome");
else
System.out.println(x + " is not a palindrome");
}
}//use "Palindromes.java" for file name
Ads 970x90
Jumat, 09 Maret 2012
Polindrom ( Java )
Editor
Aguez stw
Published
3/09/2012 07:51:00 AM
Related Posts
Load comments
Langganan:
Posting Komentar (Atom)