// 将随机数(1~10)赋给数组中的全部元素
import java.util.Random;
import java.util.Scanner;
class Ex6_10 {
public static void main(String[] args) {
Random rand = new Random();
Scanner stdIn = new Scanner(System.in);
System.out.print("元素个数:");
int n = stdIn.nextInt(); // 读入元素个数
int[] a = new int[n]; // 创建数组
a[0] = 1 + rand.nextInt(10);
for (int i = 1; i < n; i++)
do{
a[i] = 1 + rand.nextInt(10); // 1~10的随机数
}while(a[i] == a[i-1]);
for (int i = 0; i < n; i++) {
System.out.println("a[" + i + "] = " + a[i]);
}
}
}