Java基础

欢迎大家批评与建议。

增强for循环

(用来遍历集合)

实例:

int[] i = {1,4,5,7,2};
for(int s:i){
    System.out.print(s+" ");
}

三元运算符

(用来判断)

int a = 2;
int b = 5;
int max = a > b?a:b;
System.out.println(max);

static修饰符

使用static修饰符的方法与变量称为静态方法或静态变量(类方法/类变量)

可以不需要创建对象,在类中直接进行调用或使用[类名.方法名]的方式进行调用