方法
package com.bhzt;
public class Hello {
public static void main(String[] args){
age(17);
}
public static void age(int num)
{
if(num<18)
{
System.out.println("未成年");
}
}
}
重载
package com.bhzt.base;
public class OverLoad {
public void add() {
}
public void add(int a) {
}
public void add(int a,int b) {
}
public void add(int a,Long b) {
}
public void add(Long a,int b) {
}
}
递归
package com.bhzt.base;
public class Recursion {
public static void b() {
System.out.println("b");
}
public static int Factorial(int n) {
if(n==1)
{
return 1;
}
else {
return n*Factorial(n-1);
}
}
public static int getNum(int n) {
if(n<=2)
{
return 1;
}
else
{
return getNum(n-2)+getNum(n-1);
}
}
}
package com.bhzt.test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.bhzt.base.Recursion;
class RecursionTest {
@BeforeEach
void setUp() throws Exception {
}
@Test
void b() {
Recursion.b();
}
@Test
void Recursion() {
long d1=System.currentTimeMillis();
System.out.println("阶乘结果:"+Recursion.Factorial(15));
long d2=System.currentTimeMillis();
System.out.println("阶乘计算时间为:"+(d2-d1));
}
@Test
void getNum()
{
System.out.println(Recursion.getNum(24));
}
}