+ 2
how to use methods ?
3 Respuestas
+ 2
in java script:
function yourmethod(parameters){
return;
}
in java:
double namethemethod(parameters){
return parameter;
}
+ 1
you make the method with:
1) public or private.
2) type of variable being returned. (void if none)
3) name of method.4) parameters sent through when method is called.
so if we want, say, the sum of 2 integers...
public int sum(int one, int two)
{
System.out.println(one+two);
}
And in order to call the method you write
sum(2,8);
this makes 2 correspond with int one in the "sum" method, and 8 correspond with the int two in the "sum" method. In this case, it would print 10.
0
Example of a method :
public void test() {
System.out.println ("Hello World ! ") ;
}
Just write : test() ;
In the main() function, that's all !