+ 2

how to use methods ?

22nd Oct 2016, 5:39 AM
MUHAMMAD ILHAM
MUHAMMAD ILHAM - avatar
3 Respostas
+ 2
in java script: function yourmethod(parameters){ return; } in java: double namethemethod(parameters){ return parameter; }
22nd Oct 2016, 4:20 PM
Neo
Neo - avatar
+ 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.
25th Oct 2016, 8:39 PM
Bobby Turnip (Scye)
Bobby Turnip (Scye) - avatar
0
Example of a method : public void test() { System.out.println ("Hello World ! ") ; } Just write : test() ; In the main() function, that's all !
3rd Nov 2016, 11:30 PM
NASSIM LOUCHANI
NASSIM LOUCHANI - avatar