摘要:
public class Sequence { public static void main(String[] args) { int n = 5; // 0:向右,1:向下,2:向左,3:向上 int direction = 0; // 行,列 int row = 0, col = 0; int num = 0; int[] array = new int[n * n]; while (array[row * n + col] == 0) { num++; array[row * n + col] = num; switch (direction) { ... 阅读全文
摘要:
一、Random1、创建Random类型的对象: Random random = new Random();//默认构造方法Random random = new Random(10010010);//指定种子数字 2、生成随机数字: 生成随机整数:int k = random.nextInt(); 生成随机长整数:long l = random.nextLong(); 3、生成指定范围的数字: 例如生成0-10之间的随机数字: int k = random.nextInt();int j = Math.abs(k % 10); //直接方式:rand.nextInt(range);int i 阅读全文