0
import java.util.Scanner;
public class Homework
{
    static String aString;
    public Homework()
    {

    }

    public static void Check(String args[])
    {
        Scanner s = new Scanner(System.in);
        aString=s.next();
        boolean palinder;
        palinder=true;
            for(int i=0;i!=aString.length()/2;i++)
          {
            if (aString.charAt(i)!=aString.charAt(aString.length()))
                {
                   System.out.println("The word "+aString+" isn't a palinder");
                   palinder=false;
                }
          }
        if (palinder)
        {
            System.out.println("The word "+aString+" is a  palinder");
        }
    }
}

我编写了这个程序,它应该确定一个单词是否是一个 palinder,但问题是当我在 blueJ 中启动它时,程序不会加载,就像我循环一样。我不知道我写错了什么。

4

1 回答 1

0

这是解决方案。您需要显着更改当前代码。

import java.util.Scanner;

public class Homework
{
public Scanner s;
public String wordToTest;

public void HomeWork()
{
    s = new Scanner(System.in);
    wordToTest = s.next();

    Check(wordToTest);
}

public static void Check(String testWord)
{
    String aWord = "palinder";

    if (aWord.equals(testWord))
    {
        System.out.println("The word "+testWord+" is a  palinder");
    }
    else
    {
        System.out.println("The word "+testWord+" isn't a palinder");
    }

}
}

希望它会有所帮助。

于 2015-06-07T11:18:55.583 回答