miscellany: tired...
Let's get that report done tonight! Hell, why not two of 'em?
(Investigative and progress reports, yippee!)
這些感覺可能使我感覺一個正常人的樂趣嗎?
Up and down and around and down and sometimes just blessedly flat...
Please work on this some more. I cannot pass you as is. I am just
having trouble following what you have sent in.
import java.io.*;// import for using BufferedReader, BufferedWriter
public class Palindrome
{
public static void main( String args[] ) throws IOException
{
try
{
BufferedReader inputStream = new BufferedReader(new FileReader("pals.txt"));
BufferedWriter outputStream = new BufferedWriter(new FileWriter("palsout.txt"));// using BufferedWriter instead of PrintWriter
String line;
String lineCopy;
line = inputStream.readLine();// starts reading file by the line
while( line != null )
{
// strip punctuation, spaces, and special characters, then convert to lower case
String stripArray[] = { "\"", "'", ".", " ", ",", ";", ":", "!", "@", "#", "$", "%", "^", "&", "\\", "(", ")", "_", "-", "+", "=", "?", "[", "]", "{", "}", "<", ">", "/" };
lineCopy = line;
for(String charReplace:stripArray)// remove each element in stripArray from lineCopy
{
lineCopy = lineCopy.replace( charReplace,"" );
}
lineCopy = lineCopy.toLowerCase();
StringBuilder copyString = new StringBuilder(lineCopy);
copyString.reverse();// reverse the character order in copyString
if( lineCopy.equals(copyString.toString()) )// it's a palindrome
{
System.out.print( line + " Is a palindrome.\n" );
outputStream.write( line + " Is a palindrome." );
outputStream.newLine();
}
else// it's not a palindrome
{
System.out.print( line + " Is not a palindrome.\n" );
outputStream.write( line + " Is not a palindrome." );
outputStream.newLine();
}
line = inputStream.readLine();// read the next line
}
inputStream.close();
outputStream.close();
}
catch( java.io.FileNotFoundException e )
{
System.out.print("The file \"pals.txt\" must be located in the same directory as this application.");
}
}
}