Class FunctionDemo2 {
public static void Main (string[] args)
{
/*
int sum=getsum (4,6);
System.out.println ("sum=" +sum);
*/
Get (4,5));
}
public static void get (int a,int b)
{
System.out.println (A+B);
Return
}
/*
How do you define a function?
1, since the function is a separate function, then the operation of the function of the result is what first clear
Because this is the return value type in the explicit function
2. Whether unknown content is required to participate in the operation in the process of clearly defining the function.
Because it is in the argument list of the specified function (the type of the parameter and the number of arguments)
*/
Requirements: Define a function, complete the 3+4 operation, and return the result to the caller
/*
1, the result of clear function: is an integer and
2, in the process of implementing this function, whether there is unknown content to participate in the operation. No.
In fact, these two functions are defined in a definite function.
1 is the return value type in the explicit function
2. Define the parameter list of the function (type of parameter and number of parameters)
*/
/*
public static int Getsum ()
{
return 3+4;
}
*/
/*
* The functions of the above function, the result is fixed, without extensibility.
* In order to facilitate user needs, by the user to specify Addend and be addend, so that the function is meaningful.
Ideas:
1, the function result is a and, the return value type is int
2, there are unknown content to participate in the operation, there are two, the two unknown content types are int
*/
public static int getsum (int x,int y)
{
return x+y;
}
/*
Requirement: Determine whether two numbers are the same.
Ideas:
1, the result of the clear function is a Boolean
2, whether the function has unknown content to participate in the operation, there are two integers
*/
public static Boolean compare (int a,int b)
{
/*
if (a==b)
{
return true;
}
Else
{
return false;
}
*/
return a==b;
}
/*
Requirements: Define the function, compare two numbers, get a larger number
*/
public static int Getmax (int a,int b)
{
Return (a>b)? a:b;
}
}
Java learning-How to define a function and its simple practice