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