1 int没有初始化
int i,j;
System.out.println("i="+i+" j="+j); //此时会抛出错误,说没有初始化,出现下面的问题,问题说明如下:
xception in thread "main" java.lang.Error: Unresolved compilation problems:
The local variable i may not have been initialized
The local variable j may not have been initialized
at javaExeam.MaxSum.main(MaxSum.java:12)
2 static的初始化问题,如果使用static关键字,初始化默认为0.
static必须放到类中,才可以。例如类中如下:
public class MaxSum {
static int i,j;
public static void main(String[] args) {
System.out.println("i="+i+" j="+j);
}
}
3 数组的初始化,int的为0
int[][] a=new int[4][4];
System.out.println(" "+a[0][0]); //结果为0