| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Member Join Date: Jun 2005
Posts: 163
![]() | |
| |
| | #2 (permalink) |
| NamePros Member Join Date: Oct 2004
Posts: 40
![]() | Why do you need to use 'Scanner' - how are you planning on using this program? Are you just going to give it a possible palindrome at the command line? Surely all you would need to do in your main is Code:
public static void main(String [] args) {
Palindrome p = new Palindrome();
String possiblePal = args[0];
possiblePal = p.removeNoneLetters(possiblePal);
if(p.isPalindrome(possiblePal))
System.out.println("Is palindrome");
else
System.out.println("Is not palindrome");
} |
| |
| | #3 (permalink) |
| Senior Member Join Date: Sep 2005
Posts: 1,112
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Well think of it logically. take the text from command line, through args[]. Then, start 2 indexed, one at 0 and one equal to the length of the string. The first index moves forward, the second one backward. Keeping incrementing the first and decrementing the second as long as the characters match at both indexes. yous top when 2 characters are not the same, or when the 2 pointers reach the same index or the first bypasses the second. |
| |