阅读:JAVA 3& 4

  • 随机数:
Random rand = new Random(47); // 产生随机算子。47 is seed. for incovating predicatable random number
int i = rand.nextInt(100); // 100 is range of random number

Random()

“Creates a new random number generator. This constructor sets the seed of the random number generator to a value very likely to be distinct from any other invocation of this constructor. “

The seed is probably a derivative of the current time, or the current time itself. That should be enough to be “very likely to be distinct from any other invocation”. Which, in essence, is most likely what you need, most of the time.

So why have another constructor that takes a seed?

Simply put, if you want to generate the same set of random numbers over and over, you use the same seed on your Random constructor. This is useful when doing experiments on different control sets, and you don’t want to bother creating your own table of random inputs, but still want the same set of random input on a different experiment/control set.

  • 类型确定

instanceof. String i = ''; i instanceof String. However, i instanceof int will have compiler error.

  • 常量

Long 3000L/l

Double 2.33D/d

Float 3.44f/F

int i1 = 0x23;
String ii = Integer.toBinaryString(i1);
  • for-循环

for(char s: 'hello world'.toCharArray()){

}

猜你喜欢

转载自www.cnblogs.com/connie313/p/10549563.html