当前位置:网站首页>It can receive multiple data type parameters - variable parameters
It can receive multiple data type parameters - variable parameters
2022-04-23 03:13:00 【The name of the father】
One 、 Problem introduction
If you need to define a method to sum , This method can flexibly fulfill the following requirements :
- Calculation 1 The sum of two data .
- Calculation 2 The sum of two data .
- Calculation 3 The sum of two data .
- Calculation n The sum of two data ,
- It can even support calling without receiving parameters .
Two 、 effect
- The transmission parameters are very flexible , convenient 、 No parameters can be passed ,
- You can transfer a parameter Multiple parameters can be transferred
- You can transfer an array
- Variable parameters are essentially an array inside a method
Note on variable parameters :
1. There can only be one variable parameter in a formal parameter list
2. Variable parameters must be placed at the end of the formal parameter list
Format :
Format of variable parameters : data type ... Parameter name
public class MethodDemo {
public static void main(String[] args) {
sum();//1. Don't pass parameters
sum(10);//2. You can pass a parameter
sum(10,20,30);//3. Multiple parameters can be passed
sum(new int[]{10,20,40,50});//4. You can transfer an array
}
/**
* Be careful : There can only be one variable parameter in a formal parameter list
* @param nums
*/
public static void sum (int... nums){
// Be careful : Variable parameters are actually an array inside the method .nums
System.out.println(" Element number :" + nums.length);
System.out.println(" Element content :" + Arrays.toString(nums));
}
}

版权声明
本文为[The name of the father]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230311424748.html
边栏推荐
- 《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案
- .NET7之MiniAPI(特别篇):.NET7 Preview3
- After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
- Source generator actual combat
- 可以接收多种数据类型参数——可变参数
- Configure automatic implementation of curd projects
- yes. Net future
- Impact of AOT and single file release on program performance
- This new feature of C 11, I would like to call it the strongest!
- Using positive and negative traversal to solve the problem of "the shortest distance of characters"
猜你喜欢

2022年P气瓶充装培训试题及模拟考试

Laravel new route file

手机连接电脑后,QT的QDIR怎么读取手机文件路径

The most detailed in the whole network, software testing measurement, how to optimize software testing cost and improve efficiency --- hot

2022T电梯修理考试模拟100题及在线模拟考试

ASP. Net 6 middleware series - execution sequence

【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持
![[Mysql] LEFT函數 | RIGHT函數](/img/26/82e0f2280de011636c26931a74e749.png)
[Mysql] LEFT函數 | RIGHT函數

2022t elevator repair test simulation 100 questions and online simulation test

Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
随机推荐
Source generator actual combat
在.NE6 WebApi中使用分布式缓存Redis
求二叉树的叶子结点个数
svg标签中利用<polygon/>循环数组绘制多边形
Xutils3 corrected a bug I reported. Happy
EasyUI's combobox implements three-level query
Preview of converting doc and PDF to SWF file
Fight leetcode again (290. Word law)
《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案
Realize QQ login with PHP
Comprehensive calculation of employee information
“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
再战leetcode (290.单词规律)
Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful
2022山东省安全员C证上岗证题库及在线模拟考试
. net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure
Due to 3 ²+ four ²= five ², Therefore, we call '3,4,5' as the number of Pythagorean shares, and find the array of all Pythagorean shares within n (including n).
2022a special equipment related management (elevator) work license question bank and simulation examination
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
Mysql database, inconsistent index character set, slow SQL query, interface timeout