Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

  1. #1
    Super Moderator angad's Avatar
    Join Date
    Aug 2010
    Location
    nature
    Posts
    505
    Blog Entries
    132
    Rep Power
    5

    Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    Code:
    import java .io.*;
    class palindrome
    {
    	public static void main(String args[])throws IOException
    	{
    	    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    	    String s1,s2="";
    	     int i,l;
    	    char ch;
    	    System.out.println("ENTER STRING TO CHECK");
    	    s1=in.readLine();
    	    l=s1.length();
    	    for(i=l-1;i>=0;i--)
    		{
    		ch=s1.charAt(i);
    		s2=ch+s2;
    		}
    	if(s1.equals(s2))
    	      System.out.println("PALINDROME");
    	
    	else
                  System.out.println("nOT PALINDROME");
    	}
    }
    Last edited by Harsh; 11-21-2012 at 04:51 PM. Reason: Changed the code as per the comment of ravikiran cherukuri. Thanks for pointing this out.
    techforum4u.com Member!!

  2. #2
    Administrator Harsh's Avatar
    Join Date
    May 2010
    Posts
    567
    Blog Entries
    92
    Rep Power
    10

    Re: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    Nice Share!!
    " Don't limit your challenges, challenge your limits "
    (Harsh Chowdhary)

  3. #3
    Member prafic's Avatar
    Join Date
    Feb 2011
    Location
    kolkata,india
    Posts
    84
    Blog Entries
    17
    Rep Power
    0

    Re: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    good one angad...
    techforum4u.com Member!!

  4. #4

    Re: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    from where you have got such technical brain?
    techforum4u.com Member!!

  5. #5
    Super Moderator angad's Avatar
    Join Date
    Aug 2010
    Location
    nature
    Posts
    505
    Blog Entries
    132
    Rep Power
    5

    Re: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    well this is not a great program. there are other very serius and genuine brains in our forum.
    techforum4u.com Member!!

  6. #6

    Re: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    sir, can we get more such programs?
    techforum4u.com Member!!

  7. #7
    Banned cseradh's Avatar
    Join Date
    Feb 2011
    Posts
    38
    Blog Entries
    1
    Rep Power
    0

    Re: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    there are other very serius and genuine brains in our forum.
    sir, plz name dem also .. hahhahahaha
    techforum4u.com Member!!

  8. #8

    Re: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    it will always print "palindrome"
    techforum4u.com Member!!

  9. #9
    Junior Member ravikiran cherukuri's Avatar
    Join Date
    Nov 2012
    Location
    hyderabad, Andhra pradesh, India
    Posts
    1
    Rep Power
    0

    Re: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    I think the program isn't correct!
    you are checking whether the string is palindrome or not and so the loop has to start from the last index position, because palindrome is nothing but proving that the reverse of the string is also the same.
    techforum4u.com Member!!

  10. #10
    Administrator Harsh's Avatar
    Join Date
    May 2010
    Posts
    567
    Blog Entries
    92
    Rep Power
    10

    Re: Write A Program In Java To Find Whether The String Is Palindrome Or Not?

    Quote Originally Posted by ravikiran cherukuri View Post
    I think the program isn't correct!
    you are checking whether the string is palindrome or not and so the loop has to start from the last index position, because palindrome is nothing but proving that the reverse of the string is also the same.
    Thanks for pointing this out. Now the code is changed accordingly. Added to your reputation .
    " Don't limit your challenges, challenge your limits "
    (Harsh Chowdhary)

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 11-06-2011, 11:30 AM
  2. Replies: 0
    Last Post: 11-04-2011, 08:20 AM
  3. Replies: 7
    Last Post: 08-06-2011, 09:41 AM
  4. Replies: 1
    Last Post: 03-26-2011, 10:15 AM
  5. Replies: 1
    Last Post: 03-18-2011, 02:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.