Java编程语言里取随机数1,2,3的方法是什么?

Python010

Java编程语言里取随机数1,2,3的方法是什么?,第1张

提取random是在Math的方法里的

直接给你个1-100以内的随机数代码好拉

Random r=new Random()

int i1=r.nextInt()

int i2=r.nextInt(100)//返回0到100之间的随机数

double d=r.nextDouble()

float f=r.nextFloat()

byte[] c=new byte[10]

r.nextBytes(c)//生成的随机数存放在 数组c中

int sum = 0

Scanner sc = new Scanner(System.in)

int n = sc.nextInt()

for(int i=0i<=ni++)

sum += i

System.out.println(sum)

把字符串转成数组,然后用2个新数组装值,各成一行。

public static void main(String[] args) {

int[] array = new int[]{1,2,3,4,5,6}

int[] tempA = new int[array.length/2]

int[] tempB = new int[array.length/2]

for(int i = 0,j=0,k=0i <array.lengthi++){

if(i % 2 == 0){

j++

tempA[j] = array[i]

}else{

k++

tempB[k] =array[i]

}

}

}