当前位置:网站首页>Variable parameters
Variable parameters
2022-06-12 14:26:00 【Happy happy】
Variable parameters
- In the method declaration , An ellipsis after the specified parameter type (…).
- Only one variable parameter can be specified in a method , And it must be the last parameter of the method . Any ordinary parameter must be declared before it .
Code example 1
package method;
public class Demo04 {
public static void main(String[] args) {
Demo04 demo04 = new Demo04();
demo04.test(1,2,3,5,56);
}
public void test(int... i){
System.out.println(i[0]);
System.out.println(i[1]);
System.out.println(i[2]);
System.out.println(i[3]);
System.out.println(i[4]);
}
}
Operation result display
D:\apps\jdk8\bin\java.exe "-javaagent:E:\javanote\IntelliJ IDEA Community Edition 2021.1\lib\idea_rt.jar=53572:E:\javanote\IntelliJ IDEA Community Edition 2021.1\bin" -Dfile.encoding=UTF-8 -classpath D:\apps\jdk8\jre\lib\charsets.jar;D:\apps\jdk8\jre\lib\deploy.jar;D:\apps\jdk8\jre\lib\ext\access-bridge-64.jar;D:\apps\jdk8\jre\lib\ext\cldrdata.jar;D:\apps\jdk8\jre\lib\ext\dnsns.jar;D:\apps\jdk8\jre\lib\ext\jaccess.jar;D:\apps\jdk8\jre\lib\ext\jfxrt.jar;D:\apps\jdk8\jre\lib\ext\localedata.jar;D:\apps\jdk8\jre\lib\ext\nashorn.jar;D:\apps\jdk8\jre\lib\ext\sunec.jar;D:\apps\jdk8\jre\lib\ext\sunjce_provider.jar;D:\apps\jdk8\jre\lib\ext\sunmscapi.jar;D:\apps\jdk8\jre\lib\ext\sunpkcs11.jar;D:\apps\jdk8\jre\lib\ext\zipfs.jar;D:\apps\jdk8\jre\lib\javaws.jar;D:\apps\jdk8\jre\lib\jce.jar;D:\apps\jdk8\jre\lib\jfr.jar;D:\apps\jdk8\jre\lib\jfxswt.jar;D:\apps\jdk8\jre\lib\jsse.jar;D:\apps\jdk8\jre\lib\management-agent.jar;D:\apps\jdk8\jre\lib\plugin.jar;D:\apps\jdk8\jre\lib\resources.jar;D:\apps\jdk8\jre\lib\rt.jar;E:\javanote\out\production\Hello method.Demo02
The maximum number is :56
Process finished with exit code 0
Code example 2
package method;
public class Demo02 {
public static void main(String[] args) {
bigger(23.2,56.3,89.7,56,100.5);
bigger(new double[]{
90,2.3,8.4,4.9});
}
public static void bigger(double...numbers){
if (numbers.length==0){
System.out.println("no numbers");
return;
}
double a=numbers[0];
// Sort
for (int i=1;i<numbers.length;i++){
if (a<numbers[i]){
a=numbers[i];
}
}
System.out.println(" The maximum number is :"+a);
}
}
Operation result display
```bash
D:\apps\jdk8\bin\java.exe "-javaagent:E:\javanote\IntelliJ IDEA Community Edition 2021.1\lib\idea_rt.jar=53572:E:\javanote\IntelliJ IDEA Community Edition 2021.1\bin" -Dfile.encoding=UTF-8 -classpath D:\apps\jdk8\jre\lib\charsets.jar;D:\apps\jdk8\jre\lib\deploy.jar;D:\apps\jdk8\jre\lib\ext\access-bridge-64.jar;D:\apps\jdk8\jre\lib\ext\cldrdata.jar;D:\apps\jdk8\jre\lib\ext\dnsns.jar;D:\apps\jdk8\jre\lib\ext\jaccess.jar;D:\apps\jdk8\jre\lib\ext\jfxrt.jar;D:\apps\jdk8\jre\lib\ext\localedata.jar;D:\apps\jdk8\jre\lib\ext\nashorn.jar;D:\apps\jdk8\jre\lib\ext\sunec.jar;D:\apps\jdk8\jre\lib\ext\sunjce_provider.jar;D:\apps\jdk8\jre\lib\ext\sunmscapi.jar;D:\apps\jdk8\jre\lib\ext\sunpkcs11.jar;D:\apps\jdk8\jre\lib\ext\zipfs.jar;D:\apps\jdk8\jre\lib\javaws.jar;D:\apps\jdk8\jre\lib\jce.jar;D:\apps\jdk8\jre\lib\jfr.jar;D:\apps\jdk8\jre\lib\jfxswt.jar;D:\apps\jdk8\jre\lib\jsse.jar;D:\apps\jdk8\jre\lib\management-agent.jar;D:\apps\jdk8\jre\lib\plugin.jar;D:\apps\jdk8\jre\lib\resources.jar;D:\apps\jdk8\jre\lib\rt.jar;E:\javanote\out\production\Hello method.Demo02
The maximum number is :100.5
The maximum number is :90.0
Process finished with exit code 0
边栏推荐
- Redis核心配置和高级数据类型
- Axi4 increase burst / wrap burst/ fix burst and narrow transfer
- 【MySQL】数据库基本操作
- SystemC learning materials
- Details of bypassing safeseh mechanism by using modules that do not enable safeseh
- SystemC:SC_ Thread and SC_ METHOD
- Getting started alicloud haas510 open board DTU (version 2.0) --510-as
- Mémoire de l'examen d'entrée à l'université
- TestEngine with ID ‘junit-vintage‘ failed to discover tests
- Remote code injection
猜你喜欢
C secret arts script Chapter 5 (paragraph) (Section 3)
Is Shell Scripting really a big technology?
Player practice 17 xvideowidget
Server concurrency - note 1
Alicloud development board vscode development environment setup
If you want to build brand awareness, what bidding strategy can you choose?
Printing colored messages on the console with printf
Player actual combat 16 xdecode class
Des File Encryptor based on MFC framework
Communication flow analysis
随机推荐
Design of PLC intelligent slave station based on PROFIBUS DP protocol
华为设备配置BGP AS号替换
SystemC learning materials
Player actual combat 16 xdecode class
WinDbg preview debug analysis createtoolhelp32snapshot
QT database realizes page turning function
Remote code injection
Player practice 20 unpacking thread
How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem
Lua callinfo structure, stkid structure resolution
使用make方法创建slice切片的坑
【MySQL】数据库基本操作
SystemC uses SC_ report_ Handler processing log printing
How to set, reset and reverse bit
280 weeks /2171 Take out the least number of magic beans
3. Process concealment under the ring ----- continuous concealment and new opening prevention
Player actual combat 13 create qtopengl project to promote window control and reload qoopenglwedge
Introduction to functions (inline functions and function overloading)
Vs2012: cannot assign a value of type 'char *' to an entity of type 'lpwstr'
Getting started alicloud haas510 open board DTU (version 2.0) --510-as