package?com.heheda;
import?java.util.Arrays;
public?class?helloworld?{
public?static?void?main(String[]?args)?{
helloworld?hello?=?new?helloworld();//創(chuàng)建實例化對象
int[]?nums?=?hello.getArrays(8);//8是數(shù)組的長度,一共從你定義方法得到8個數(shù)
System.out.println(Arrays.toString(nums));//打印輸出在控制臺
}
//你自己定義得到數(shù)組的方法,傳的參數(shù)為整數(shù)
public?int[]?getArrays(int?length){
int[]?nums?=?new?int[length];//創(chuàng)建數(shù)組
//循環(huán)遍歷,將小于100的數(shù)每次遍歷存入nums中
for(int?i=0;i?<?nums.length;i++){
nums[i]?=?(int)(Math.random()*100);?
}
//返回nums
return?nums;
}
}
注釋都給你寫了,自己看下