Creating Methods that Return a Value
+4
ekkoekko
nicolai
Hyegi
Admin
8 posters
Page 2 of 2 • 1, 2
- kathrynmotoGuru
- Posts : 10
Join date : 2018-08-17
Re: Creating Methods that Return a Value
Mon Aug 20, 2018 2:33 pm
ekkoekko wrote:Can a method return two values?
You can't return two values. However, you can return a single value that is a struct that contains two values. You can return only one thing from a function. Either you make a struct which contains all the things you want to return, or you pass some function parameters by reference
- JUNGKOOKGuru
- Posts : 10
Join date : 2018-08-20
Re: Creating Methods that Return a Value
Mon Aug 20, 2018 4:03 pm
Hala, sa pagkaka alam ko lang Oo hahahaHyegi wrote:Can I have a return statement in a void method?
- johnarnoldGuru
- Posts : 10
Join date : 2018-08-22
Re: Creating Methods that Return a Value
Wed Aug 22, 2018 3:21 pm
example.
var x = myFunction(4, 3); // Function is called, return value will end up in x
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
The result in x will be:
12
var x = myFunction(4, 3); // Function is called, return value will end up in x
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
The result in x will be:
12
- johnarnoldGuru
- Posts : 10
Join date : 2018-08-22
Re: Creating Methods that Return a Value
Wed Aug 22, 2018 3:24 pm
Re: Creating Methods that Return a Value
Wed Aug 22, 2018 3:27 pm
JUNGKOOK wrote:Hala, sa pagkaka alam ko lang Oo hahahaHyegi wrote:Can I have a return statement in a void method?
It does not need to contain a return statement, but it may do so. In such a case, a return statement can be used to branch out of a control flow block and exit the method and is simply used like this: return; If you try to return a value from a method that is declared void , you will get a compiler error.
Re: Creating Methods that Return a Value
Wed Aug 22, 2018 4:18 pm
janna wrote:ekkoekko wrote:What does the void do in a method?
From Wikibooks, open books for an open world. void is a Java keyword. Used at method declaration and definition to specify that the method does not return any type, the method returns void .
Void doesn't return anything; it tells the compiler the method doesn't have a return value. void means it returns nothing.
Page 2 of 2 • 1, 2
Permissions in this forum:
You cannot reply to topics in this forum
|
|