可变参数
package com.xqstudy.method;
public class Demo3 {
public static void main(String[] args) {
Demo3 demo3 = new Demo3();
demo3.test(1,2,3,4,5,63);
}
public void test(int... i){
System.out.println(i[0]);
System.out.println(i[2]);
System.out.println(i[1]);
System.out.println(i[3]);
System.out.println(i[4]);
System.out.println(i[5]);
}
}
递归
package com.xqstudy.method;
public class Demo4 {
//递归思想
public static void main(String[] args) {
System.out.println(f(4));
}
//阶乘 递归
//5! 5*4*3*2*1
public static int f(int n){
if (n==1){
return 1;
}else {
return n*f(n-1);
}
}
}