Programming Logic and Design
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
Admin
Admin
Admin
Posts : 7
Join date : 2018-08-07
https://jenreyes.forumotion.com

Method with no Parameters and Method that require Parameters Empty Method with no Parameters and Method that require Parameters

Tue Aug 07, 2018 12:45 pm
Using Methods with no Parameters

The main program and the called method each contain only data items that are needed at the local level. The main program does not know about or have access to the variables and constant.

Creating Methods that Require Parameters

Some methods require information to be sent in from the outside. When a program passes a
data item to a method, the data item is an argument to the method , or more simply, an
argument. When the method receives the data item, it is a parameter to the method , or more
simply, a parameter. Parameter and argument are closely related terms. A calling method
sends an argument to a called method. A called method accepts the value as its parameter.

Creating Methods that Require Multiple Parameters

You create and use a method with multiple parameters by doing the following:

You list the arguments within the method call, separated by commas.
You list a data type and local identifier for each parameter within the method header’s
parentheses, separating each declaration with a comma. Even if multiple parameters are
the same data type, the type must be repeated with each parameter.


Last edited by Admin on Wed Aug 08, 2018 2:31 pm; edited 1 time in total
avatar
Myleinne
Guru
Guru
Posts : 10
Join date : 2018-08-07

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Tue Aug 07, 2018 1:49 pm
the values of variables declared locally within a method can be used by a calling method, but not by other methods?
avatar
Myleinne
Guru
Guru
Posts : 10
Join date : 2018-08-07

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Tue Aug 07, 2018 1:51 pm
what are the type of parameter?
avatar
Myleinne
Guru
Guru
Posts : 10
Join date : 2018-08-07

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Tue Aug 07, 2018 1:52 pm
ano po pag kakaiba ng parameter sa arguments?
avatar
Myleinne
Guru
Guru
Posts : 10
Join date : 2018-08-07

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Tue Aug 07, 2018 1:55 pm
when a variable is used as an argument in a method call, it can have the same identifier as the parameter in the method header po ba?
avatar
Myleinne
Guru
Guru
Posts : 10
Join date : 2018-08-07

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Tue Aug 07, 2018 1:59 pm
what if po wala ako nilagay na parameter sa method that require a parameter?
avatar
Nicole12
Guru
Guru
Posts : 11
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:16 pm
Myleinne wrote:the values of variables declared locally within a method can be used by a calling method, but not by other methods?
when a variable is declared locally within a method, its value cannot be used by other methods. if its value is needed by a calling method, the value must be returned from the method.
avatar
Nicole12
Guru
Guru
Posts : 11
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:19 pm
Myleinne wrote:ano po pag kakaiba ng parameter sa arguments?
A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters. Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function.
avatar
Nicole12
Guru
Guru
Posts : 11
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:20 pm
Myleinne wrote:what are the type of parameter?
There are four different ways of passing parameters to a method in C#. The four different types of parameters are
· Value
· Out
· Ref
· Params
avatar
Nicole12
Guru
Guru
Posts : 11
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:22 pm
Myleinne wrote:what if po wala ako nilagay na parameter sa method that require a parameter?
if a method could not recieve parameters, you would have to use global variables or write an infinite number of methods to cover every possible situations
avatar
Nicole12
Guru
Guru
Posts : 11
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:27 pm
what is a parameter list ?
avatar
Nicole12
Guru
Guru
Posts : 11
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:28 pm
what is a actual parameters and formal parameter?
avatar
Nicole12
Guru
Guru
Posts : 11
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:35 pm
What will happen to the values in main after being sent to this method??
nt a = 2, b = 3, c = 4, answer = 2;
answer = discriminant(a, b, c);
System.out.println("The discriminant is " + answer);
------------------------------------------------------------
public static int discriminant(int x, int y, int z)
{
int disc;
disc = y*y - 4*x*z;
return disc;
}
avatar
Maridel
Guru
Guru
Posts : 10
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:40 pm
Nicole12 wrote:What will happen to the values in main after being sent to this method??
nt a = 2, b = 3, c = 4, answer = 2;
answer = discriminant(a, b, c);
System.out.println("The discriminant is " + answer);
------------------------------------------------------------
public static int discriminant(int x, int y, int z)
{
   int disc;
   disc = y*y - 4*x*z;
   return disc;
}
It is possible for a method to change a value in main by returning and saving the value after the method is complete. The limitation to this concept is that only ONE value can be returned from a method.
In this example, answer was initially 2, but after execution of the method and new assignment to answer, it now has the value -23.
avatar
Maridel
Guru
Guru
Posts : 10
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:42 pm
Nicole12 wrote:what is a actual parameters and formal parameter?
In Russian "parameters" are called "formal parameters", while "arguments" are called "actual parameters".
avatar
Maridel
Guru
Guru
Posts : 10
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:42 pm
Myleinne wrote:ano po pag kakaiba ng parameter sa arguments?
In Russian "parameters" are called "formal parameters", while "arguments" are called "actual parameters".
avatar
Maridel
Guru
Guru
Posts : 10
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:43 pm
Myleinne wrote:ano po pag kakaiba ng parameter sa arguments?
A parameter is the variable which is part of the method’s signature (method declaration). An argument is an expression used when calling the method.
avatar
Maridel
Guru
Guru
Posts : 10
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 1:49 pm
additional info: The method definition specifies the names and types of any parameters that are required. When calling code calls the method, it provides concrete values called arguments for each parameter. The arguments must be compatible with the parameter type but the argument name (if any) used in the calling code does not have to be the same as the parameter named defined in the method.
avatar
Maridel
Guru
Guru
Posts : 10
Join date : 2018-08-08

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

Wed Aug 08, 2018 2:05 pm
what if nakalimutan ko mag lagay ng data type sa parameter since yung isa ko naman may data type na and same lang naman sila ng data type?
Sponsored content

Method with no Parameters and Method that require Parameters Empty Re: Method with no Parameters and Method that require Parameters

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