Share
Go down
Guru
Guru
Posts : 10
Join date : 2018-08-17
View user profile

Re: Creating Methods that Return a Value

on 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
Guru
Guru
Posts : 10
Join date : 2018-08-20
View user profile

Re: Creating Methods that Return a Value

on Mon Aug 20, 2018 4:03 pm
Hyegi wrote:Can I have a return statement in a void method?
Hala, sa pagkaka alam ko lang Oo hahaha
Guru
Guru
Posts : 10
Join date : 2018-08-22
View user profile

Re: Creating Methods that Return a Value

on 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
Guru
Guru
Posts : 10
Join date : 2018-08-22
View user profile

Re: Creating Methods that Return a Value

on Wed Aug 22, 2018 3:24 pm
Admin
Posts : 11
Join date : 2018-08-07
Age : 19
View user profilehttp://rachellann.forumotion.com

Re: Creating Methods that Return a Value

on Wed Aug 22, 2018 3:27 pm
JUNGKOOK wrote:
Hyegi wrote:Can I have a return statement in a void method?
Hala, sa pagkaka alam ko lang Oo hahaha

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.
Admin
Posts : 11
Join date : 2018-08-07
Age : 19
View user profilehttp://rachellann.forumotion.com

Re: Creating Methods that Return a Value

on 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.
Sponsored content

Re: Creating Methods that Return a Value

Back to top
Permissions in this forum:
You cannot reply to topics in this forum