1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | package com.java; import java.util.Scanner; public class Palindrom { public static void main(String args[]) { String original, reverse=""; Scanner in = new Scanner(System.in); System.out.println("Enter a string to check if it is a palindrome : "); original = in.nextLine(); int length = original.length(); for ( int i = length - 1 ; i >= 0 ; i-- ) reverse = reverse + original.charAt(i); if (original.equals(reverse)) System.out.println("Entered string is a palindrome."); else System.out.println("Entered string is not a palindrome."); } } /*Output: Enter a string to check if it is a palindrome : madam Entered string is a palindrome. */ |
It's all about Java development. A place mainly for java programmers.
Saturday, 10 March 2012
Palindrome program
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment