Recursive algorithm:
One problem: write the Fibonacci number using a recursive algorithm.
Second problem:! N write algorithms.
Comparison of the two methods, the recursive method clear thinking, algorithm is simple and straightforward.
Recursion is a easy to write and easy to think of the algorithm for processing functions associated with itself.
static: a modifier main function
静态修饰符:标识成员可以被类直接调用
static: 五种
1:静态成员变量
2:静态成员方法
3:静态代码块
4:静态内部类 X
5:静态导包
static:可以被类名直接调用 类名.属性名
类名.方法名
static与非static之间的重要区别:
区别1:
static修饰的成员是随着类的加载而加载(优先)
非static成员是随着对象的创建而加载
区别2:
静态方法|静态代码块只能调用静态成员,非静态成员是不能直接调用的,创建对象(不能使用this关键字)
非静态方法可以直接调用非静态成员,也可以调用静态成员.类的对象进行调用静态成员
区别3:
静态成员对于多个对象而言是共享的
非静态成员对于多个对象是彼此独立的
1 public class StaticTest { 2 3 String name; 4 static int number=10; //静态成员变量 5 6 public static void main(String[] args) { 7 Person p=new Person(); 8 Person p1=new Person(); 9 p.setName("张三"); 10 p.setAge(16); 11 System.out.println("我叫:"+p.getName()+",今年:"+p.getAge()); 12 System.out.println("我叫:"+p1.getName()+",今年:"+p1.getAge()); 13 14 doSome(); 15 16 System.out.printf("HelloWorld"); 17 18 System.out.println(Person.add(1,2,3,4,5,6));; 19 20 System.out.println(Person.c(5)); 21 System.out.println(Person.c(5)); 22 } 23 24 public static void sayHello(String name){ //静态函数 25 System.out.println(name+",您好!"); 26 } 27 28 static{ //静态代码块 最优先的 29 System.out.println("这是静态代码块。。。。"); 30 } 31 }