0
Q:

how to create a method java

//declare a function like this:
void function(int parameter1)
{
	//function body
}
//call the function like this:
function(1);
4
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;
}
5
public class MyClass {
  static void myMethod() {
    
    // a method comes before the main method
    // use source for more information
    // code to be executed
  }
}
 
0
public class MyClass {
  static void myMethod() {
    // code to be executed
  }
}
 
0

New to Communities?

Join the community