随机产生25个100以内的无重复随机数并排序

import java.util.Random;

public class Practice_02 {
	public static void main(String[] args){
		Random r = new Random();
		int[] cob = new int[25];
		
		for(int i=0;i<25;i++){
			int b = r.nextInt();
			int a = Math.abs(b%100);
			cob[i] = a;	
			for(int h=0;h<i;h++){
				if(cob[h] == cob[i]){
					i--;
					break;
				}
			}
		}
		
		int tmp;
		for(int j=0;j<cob.length;j++){
			for(int k=0;k<(cob.length-j-1);k++){
				if(cob[k]>cob[k+1]){
					tmp = cob[k];
					cob[k] = cob[k+1]; 
					cob[k +1] =tmp; 
				}
			}
		}
		
		for(int z=0;z<cob.length;z++){
			System.out.print(cob[z]+" ");
		}
	}
}

你可能感兴趣的:(java)