Use of no return value method with parameters in Java
Sometimes the execution of a method depends on certain conditions, in other words, it is necessary to provide additional information to accomplish a particular function through the method. For example, the real-life rice cooker can achieve the function of "cooking rice", but only if we have to provide the ingredients, if we do not provide anything, it is really "paddle". we can receive external incoming data information by adding a parameter list to the method, which can be any basic type data or reference type data.
Let's take a look at a method with parameters but no return value:
650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537d78330001694006110113.jpg"/>
The code above defines a show method with a parameter name, which implements the output welcome message.
Calling the parameter method is similar to invoking the syntax of the parameterless method, but must pass in the actual parameter value when called
650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537d78620001ffe103210024.jpg"/>
For example:
650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537d789500011a4b04830112.jpg"/>
Operation Result: 650) this.width=650; "src=" http://img.mukewang.com/537d794d0001c05401360025.jpg "/>
Many times, we refer to the parameter defining the method as a formal parameter, which is used to define the number and type of parameters that the method needs to pass in, and to call the method when the argument is called an argument, which is the value passed to the method that is actually processed.
A question that must not be overlooked:
1. When calling the parameter method, the number, type, and order of the arguments must be guaranteed to correspond to the parameter one by one.
650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537efa4100013c4106270249.jpg"/>
2. When calling a method, the argument does not need to specify a data type, such as 650) this.width=650; "src=" http://img.mukewang.com/537f01f7000117e402470024.jpg "/>
3, the parameters of the method can be basic data types, such as int, double, etc., can also be reference data type, such as String, array, etc.
650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537f0298000146d707110307.jpg"/>
4, when the method parameter has multiple, multiple parameters are separated by commas
650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537f038d0001cac204930144.jpg"/>
Code:
public class HelloWorld {
public static void Main (string[] args) {
Create object, object named Hello
HelloWorld Hello = new HelloWorld ();
Call the method and pass in the scores of the two courses
Hello.calcavg (94, 81);
}
/*
* Function: Calculate the average score of two courses test results and output the average score
* Define a method that contains two parameters to pass the scores of two courses
*/
public void Calcavg (int java,int html) {
Double avg = (java+html)/2.0;
System.out.println ("Mean score:" +AVG);
}
}
Operation Result:
Average score: 87.5
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1548006
Java Basics---Use of no return value method with parameters in Java (39)