TXT

GetNum

By Douglas Hill,2014-08-17 19:50
14 views 0
GetNum

import java.util.Random;

    public class GetNum {

     public static int i = 0;

     public static void main(String[] args) {

     Random r = new Random();

     int arr[] = new int[10];

     int temp = 0;

     for (; i < 10;) {

     temp = r.nextInt(100);//生成100-100的数

     if (i == 0) {

     arr[i] = temp;

     i++;

     } else {

     for (int j = 0; j < i; j++) {

     if (arr[j] == temp) {

     break;

     } else if (j == i - 1) {//判断所有的arr[j]是否都不等于temp;不等就把temp赋值给arr[i]

     arr[i] = temp;

     i++;

     // break;

     }

     }

     }

     }

     for (int n = 0; n < arr.length; n++) {//对你取的10个随机数排序

     for (int j = n + 1; j < 10; j++) {

     if (arr[n] > arr[j]) {

     temp = arr[n];

     arr[n] = arr[j];

     arr[j] = temp;

     }

     }

     System.out.print(arr[n] + " ");

     }

     }

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com