//declare a function like this: void function(int parameter1) { //function body } //call the function like this: function(1);
public static void main(String[] args) { int length=getLength(); System.out.println("Your length is: "+length); } //methods are outside of main method public static int getLength() { int length=5; return length; }
public class MyClass { static void myMethod() { // a method comes before the main method // use source for more information // code to be executed } }
public class MyClass { static void myMethod() { // code to be executed } }