random.nextInt(2)這是什么意思?
下面代碼中的 ? ? random.nextInt(2) ? ?怎么理解? public String createCode(){ String code = ""; Random random = new Random(); for(int i=0;i<5;i++){ code+=random.nextInt(2)==0?(char)('A'+random.nextInt(26)):(char)('a'+random.nextInt(26)); } return code; }
2017-03-30
隨機(jī)生成一個(gè)整數(shù),值域 [0, 2)