java函數(shù)怎么調(diào)用數(shù)組 java怎么使用隨機(jī)抽取數(shù)組里的數(shù)據(jù)?
java怎么使用隨機(jī)抽取數(shù)組里的數(shù)據(jù)?Random r = new Random()System.out.println(b[r.nextInt(3)])r.nextInt(3)就是隨機(jī)取得0 1 2
java怎么使用隨機(jī)抽取數(shù)組里的數(shù)據(jù)?
Random r = new Random()
System.out.println(b[r.nextInt(3)])r.nextInt(3)就是隨機(jī)取得0 1 2這三個(gè)數(shù)中的其中一個(gè),然后當(dāng)做你數(shù)組的下標(biāo),就隨機(jī)抽取了
Java隨機(jī)抽取人名完整代碼?
public class test { public static void main(String[] args) { //定義人名數(shù)組 String [] name = {"張三","李四","王五","八神庵","不知火舞","大蛇","景天","唐雪見","李逍遙","趙靈兒"}//隨機(jī)生成數(shù)組下標(biāo)、 int num = (int)(Math.random() * 1000)//對(duì)生成的隨機(jī)數(shù)進(jìn)行判斷,如果小于數(shù)組下標(biāo),就跳出循環(huán)while (num>name.length-1) { if (num