Can I declare a method in main Java?

No, you can’t (directly *) defined methods inside other methods in Java (and the main method is no special case here). What you want to do is to put the method in the same class as main . If main needs to call it without creating an instance of the class, then it needs to be static , but it need not be public .

Read more

Can we declare methods in Java?

Java requires that a method declare the data type of the value that it returns . If a method does not return a value, it must be declared to return void . … Methods use the return operator to return a value. Any method that is not declared void must contain a return statement.

Read more