nextInt用法
import java.util.*;class Value {
int i;
public Value (int i){
this.i = i;
}
}
public class FinalData {
private static Random rand = new Random(47);
private String id;
public FinalData(String id){
this.id = id;
}
private final int valueOne = 9;
private static final int VALUE_TWO = 99;
public static final int VALUE_THREE = 39;
private final int i4 = rand.nextInt(20);
static final int INT_5 = rand.nextInt(20);
private Value v1 = new Value(11);
private final Value v2 = new Value(22);
private static final Value VAL_3 = new Value(33);
private final int[] a = {1,2,3,4,5,6};
public String toString(){
return id + ": " + "i4 = " + i4 + ", INT_5 = " +INT_5;
}
public static void main(String[] args){
FinalData fd1 = new FinalData("fd1");
fd1.v2.i++;
//fd1.valueOne++;
fd1.v1 = new Value(9);
for(int i = 0;i < fd1.a.length;i++)
fd1.a[i]++;
// fd1.v2 = new Value(0);
// fd1.a = new int [3];
System.out.println(fd1);
System.out.println("Creatint new FinalData");
FinalData fd2 = new FinalData("fd2");
System.out.println(fd1);
System.out.println(fd2);
}
}
上面程序的输出结果是这样的:
fd1: i4 = 15, INT_5 = 18
Creatint new FinalData
fd1: i4 = 15, INT_5 = 18
fd2: i4 = 13, INT_5 = 18
在这里想向各位请教一下:这个程序是怎么执行的,为什么会是这个结果,还有程序中random(47)还有nextInt(20)起的作用是什么?