可变参数
package method;
import javax.swing.*;
public class Demo04 {
public static void main(String[] args) {
//调用可变参数的方法
printMax(34,3,3,2,56.5);
printMax(new double[]{1, 2, 3});
}
public static void printMax(double...numbers) {
if (numbers.length == 0) {
System.out.println("No argument passed");
return;
}
double result = numbers[0];
//排序!
for (int i = 1; i < numbers.length; i++) {
if (numbers[i] > result) {
result = numbers[i];
}
}
System.out.println("The max value is" + result);
}
};
递归
package method;
public class Demo06 {
//递归思想
public static void main(String[] args) {
System.out.println(f(5));
}
public static int f(int n){
if (n==1){
return 1;
}else{
return n*f(n-1);
}
}
}