Java知识点总结基础篇之阶乘

public class Multiply {

public static int multiply(int num) {

if (num < 0) {

System.out.println("请输入大于0的数!");

return -1;

} else if (num == 0 || num == 1) {

return 1;

} else {

return multiply(num - 1) * num;

}

}

public static void main(String[] args) {

System.out.println(multiply(8));

}

}

你可能感兴趣的:(Java知识点总结基础篇之阶乘)