剔除数组中重复操作

品高软件招聘题目:无序不重复输出0-9十个数字,输出三次;

package training1018;
public class Number {
	public static void main(String[] args) {
		int arr[] = new int[10];
        for (int n = 0; n < 3; n++) {
			int i = 0;
			while (i < arr.length) {
				boolean b = true;
				double r = Math.random();
				double r1 = r * 10;
				int r2 = (int) r1;
				for (int j = 0; j < i; j++) {
					if (r2 == arr[j]) {
						b = false;
						break;
					}
				}
				if (b) {
					arr[i] = r2;
					System.out.print(arr[i]);

					if (i < arr.length - 1) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
					i++;
				}
			}
		}
	}
}

你可能感兴趣的:(剔除数组中重复操作)