package Tang_002; public class ChangArgs002 { public static void main(String[] args) { //求最大值 Count05 c = new Count05(); int maxNum = c.max(5,3,9,7); System.out.println("最大值:"+ maxNum); } } class Count05{ public int max(int num,int... other){ // 可变参数写在所有参数后面 //num = 5; other[] = {3.9.7} //默认第一个传递的数字 是最大值 int max = num; for (int i = 0 ;i < other.length; i++){ // 暂时的最大值 挨个跟other中的数字进行比较 if (other[i] > max){ max = other[i]; } } return max; } }
ChangArgs002
最新推荐文章于 2024-07-22 22:58:19 发布