Tuesday 15 June 2010

java - Checking to see if a string is a palindrome or not -


I'm very close to ending one of my practice problems which is related to a palindrome and string parameter and I'm the main method The method to call every time I compile my code, it compiles it, but then when I go to input data it keeps running and does not result in me What to do? The problem just asks to make a method which checks that it is an illusion, my main method is that it is bothering me.

This is my code:

  import java.util. *; Public class TestisPalindrome {public stable boolean isPalindrome (string str) {int left = 0; Int correct = str.length () -1; While (left and lieutenne; right) {if (str.charAt (left)! = Str.charAt (right)) {return false; }} ++ left; right --; Back true; } Public static zero main (string [] args) {scanner scan = new scanner (System.in); System.out.println ("Enter a string to see if this is a palindrome or not:"); String st1 = scan.nextLine (); Println (isPalindrome (st1)); }}    

correct & amp; Left wage increase while loop

  while (left & lt; right) {if (str.charAt (left)! = Str.charAt (right)) {Details are false; } Left ++; right --; }    

No comments:

Post a Comment