当前位置:网站首页>Peut recevoir plusieurs paramètres de type de données - paramètres variables
Peut recevoir plusieurs paramètres de type de données - paramètres variables
2022-04-23 03:13:00 【Son nom est père.】
Un.、Introduction du problème
Si vous devez définir une méthode de sommation,Cette méthode est flexible pour répondre aux exigences suivantes:
- Calcul1Somme des données.
- Calcul2Somme des données.
- Calcul3Somme des données.
- CalculnSomme des données,
- Il est même possible de ne pas recevoir d'arguments pour les appels.
2.、Action
- Les paramètres de transmission sont très flexibles,Pratique、 Peut ne pas passer les paramètres,
- Vous pouvez transférer un paramètre Plusieurs paramètres peuvent être transférés
- Vous pouvez transférer un tableau
- Les paramètres variables sont essentiellement un tableau à l'intérieur de la méthode
Considérations relatives aux paramètres variables:
1.Il ne peut y avoir qu'un seul paramètre variable dans une liste de paramètres formels
2.Les paramètres variables doivent être placés à l'arrière de la liste des paramètres formels
Format:
Format des paramètres variables:Type de données...Nom du paramètre
public class MethodDemo {
public static void main(String[] args) {
sum();//1.Ne pas passer de paramètres
sum(10);//2.Vous pouvez passer un paramètre
sum(10,20,30);//3.Vous pouvez passer plusieurs paramètres
sum(new int[]{10,20,40,50});//4.Vous pouvez transférer un tableau
}
/**
* Attention!:Il ne peut y avoir qu'un seul paramètre variable dans une liste de paramètres formels
* @param nums
*/
public static void sum (int... nums){
//Attention!: Les arguments variables sont en fait un tableau à l'intérieur de la méthode .nums
System.out.println("Nombre d'éléments:" + nums.length);
System.out.println("Contenu de l'élément:" + Arrays.toString(nums));
}
}

版权声明
本文为[Son nom est père.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230311424748.html
边栏推荐
- 先中二叉建树
- 由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
- Source generator actual combat
- TP5 multi conditional where query (using PHP variables)
- Swap the left and right of each node in a binary tree
- Laravel's own paging query
- 2022年度Top9的任务管理系统
- ASP.NET 6 中间件系列 - 执行顺序
- svg标签中利用<polygon/>循环数组绘制多边形
- Course design of Database Principle -- material distribution management system
猜你喜欢

Xamarin effect Chapter 22 recording effect

利用栈的回溯来解决“文件的最长绝对路径”问题

C WPF UI framework mahapps switching theme

A set of combination boxing to create an idea eye protection scheme

一文了解全面静态代码分析

由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。

IOTOS物联中台对接海康安防平台(iSecure Center)门禁系统

Tencent video price rise: earn more than 7.4 billion a year! Pay attention to me to receive Tencent VIP members, and the weekly card is as low as 7 yuan

MYSQL04_ Exercises corresponding to arithmetic, logic, bit, operator and operator

Judge whether there is a leap year in the given year
随机推荐
c#语法糖模式匹配【switch 表达式】
C syntax sugar empty merge operator [?] And null merge assignment operator [? =]
Find the number of leaf nodes of binary tree
MYSQL_ From mastery to abandonment
C语言实现通讯录----(静态版本)
Drawing polygons with < polygon / > circular array in SVG tag
Laravel new route file
A set of combination boxing to create an idea eye protection scheme
【鉴权/授权】自定义一个身份认证Handler
2022年度Top9的任务管理系统
C read / write binary file
2022 P cylinder filling training test questions and simulation test
Configuration table and page information automatically generate curd operation page
ASP.NET 6 中间件系列 - 执行顺序
C introduction of variable parameter params
一套关于 内存对齐 的C#面试题,做错的人很多!
中后二叉建树
Establishing and traversing binary tree
2022A特种设备相关管理(电梯)上岗证题库及模拟考试
Creating wechat voucher process with PHP