这就是我必须解决的问题。我需要保留已经写好的内容,但我不知道如何使用循环和 charAt() 来查找回文。输入的是在终端行中写入字符串所需的代码,因此我无法输入任何内容。有什么建议么?
import java.io.*;
import java.util.*;
public class Palindrome
{
public static void main (String[] args) throws IOException
{
try // WE WILL TALK ABOUT EXCEPTIONS EVENTUALLY - JUST PUT ALL YOUR CODE IN THIS TRY BLOCK
{
// --------------------------------------------------------------------------------------------------------
if (args.length == 0)
{
System.out.println("FATAL ERROR: Must enter a word on the command line!\n");
System.exit(0);
}
String word = args[0];
boolean isPalindrome=true;
// --------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
if (isPalindrome)
System.out.println( word + " IS a palindrome." );
else
System.out.println( word + " NOT a palindrome." );
}
catch ( Exception e )
{
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
System.out.println("EXCEPTION CAUGHT: " + sw.toString() );
System.exit( 0 );
}
} // END main
} //END CLASS Palindrome