Hannah
4
Q:

java how to define a function

//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

New to Communities?

Join the community