随机数
import java.util.Random;
public class Main {
public static void main(String[] args) {
Random r = new Random();
int data = r.nextInt(10);
//0-9之间的随机数;不包括10
int data2 = data + 1;
//1-10之间的随机数;
System.out.println(data);
}
}
数组
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int[] ages = new int[]{1, 2, 3, 4};
//简化写法;
int[] ages2 = {12, 24, 36};
ages[2] = 1;
System.out.print(ages[2]);
int len = ages.length;
//不需要括号
}
}