Question:
Palindrome help - java?
Zuilee
2012-05-10 01:01:16 UTC
Aims:

Develop programming and problem solving skills and learn basic data structures by
building a Java application using ADT stack and ADT queue.

Requirements:

You should develop a Java program RecognisingPalindrome.java, which reads any given text fi le, separates the entire text into individual characters (letters, digits,punctuation marks, special symbols, etc.), and recognises whether the sequence of letters and digits in the text is a palindrome. Your program should take into account only English letters and digits in the text, but not other characters and spaces, as well as it should not discriminate between the upper- and lower-case letters. The program should implement a nonrecursive recognition algorithm, using the reference-based implementations of both the ADT stack and ADT queue.

Your Java program should be placed into a single source le RecognisingPalindrome.java, which includes all the interfaces, classes, and methods you used. The compiled application should run from a command line: java RecognisingPalindrome and display the input fi le name, the result of its recognition, the total number of characters in the text, and the total number of letters and digits in the text as follows (of course, the fi le names and the actual numbers may di er):
example;
File palin.txt: a palindrome (951 characters; 839 letters/digits) or
File plain.txt: not a palindrome (951 characters; 839 letters/digits)

Comments at the very beginning of your source fi le must give clear instructions, which explain how to compile and run your application. The scheme below is expected from your program.

*does not require Graphical User Interface (GUI).

now these are the requirements (scheme):
*Clear commenting of the code and full instructions to compile and run the program
*Structure: appropriately de ned class(es), instance variables, instance and class methods, etc.
*Clear interaction with the user (self-explanatory prompts, handling illegal input data)
*Use of try/catch/ nally blocks to handle exceptions
*Reading a text le and separating the text into individual characters
*Proper exclusion of characters which are not letters and digits
*Proper handling of upper- and lower-case characters
*Correct building of a stack and a queue of individual letters and digits
*Correct determining whether the input text is or is not a palindrome


I DO NOT know what to do!!


symbols such as "#$%^&*"........can be ignored between the text
Three answers:
Casper
2012-05-10 04:31:14 UTC
is it a must to use Stack or Queue???
Blain Rinehart
2012-05-10 08:13:41 UTC
Make a new string that is the reverse of the first string (using a for loop).

test if the new string is equal to the first one. If it is, boom, it's a palindrome.



Example:



"winner" is not equal to "renniw"

"racecar" is equal to "racecar"



Example:



public static boolean isPalindrome(String word) {

int left = 0; // index of leftmost unchecked char

int right = word.length() -1; // index of the rightmost



while (left < right) { // continue until they reach center

if (word.charAt(left) != word.charAt(right)) {

return false; // if chars are different, finished

}

left++; // move left index toward the center

right--; // move right index toward the center

}



return true; // if finished, all chars were same

}
James Bond
2012-05-10 11:05:13 UTC
static boolean ispalindrome(String a)

{

int i=0,j=a.length()-1;

for(;


return true;

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...