Java says this method has a constructor name

I want to return the value of my array plus the return value of the recursive call

But for some reason, Java doesn't want to have a method name after the constructor

In addition, when I try to convert a method to another method, I make an error when using ispalindrome

I changed my program, but I still encountered errors

public class ispalindrome
{
    /**
     * This is the main entry point for the application
     * @return 
     */
    public static boolean main(String[] args) 
    {

    String[] word = {"KayaK","Desserts,I stressed"};



    boolean ispalindrome(String[] array,String s,String i)
    {

        if(i.charAt(0) == s.charAt(0))
        {
            System.out.println("You entered a palindrome");
            return true;
        }
        else
        {
            System.out.println("You didn't entered a palindrome");
        }
    }


        try 
        {
            system.in.read();
        } 
        catch (Throwable t) 
        {

        }
}

}

Solution

You cannot use a class name as the name of a method The only "method" that can share a name with a class is the constructor

One solution is to rename your class from ispalindrome to palindromefinder or something This can also be better consistent with the Java Naming Convention

Editor: Please note that you have never actually invoked your method in main. You tried to assign a local variable to ispalindrome This does not actually call the method You need to call this method with ispalindrome (... Put your parameters here...) and store the result in a variable with an unused name

Also note that a method can only return a single value (single primitive or single object) If you really want to return an array and a Boolean value (I'm not sure you do), you must store them in an object and return the object

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>