从0到100随机抽10个不同的数,然后放入数组中。再按顺序打印出来

来源:互联网 发布:linux git 使用 编辑:程序博客网 时间:2024/05/18 02:46
import java.util.Random;public class Qushu_dayin {  public static void main(String[] args) {  // TODO Auto-generated method stub       int shu[]=new int[10];       int temp=0;//用来前后两数的交换更替      boolean b=true;//判断是否提前排序完毕的标志      Random ran=new Random();      for(int i=0;i<shu.length;){       shu[i]=ran.nextInt(101);       if(check(shu,shu[i],i)){        i++;       }      }       for(int i=0;i<shu.length-1;i++){        b=true;        for(int j=0;j<shu.length-i-1;j++){         if(shu[j]>shu[j+1]){          b=false;          temp=shu[j];          shu[j]=shu[j+1];             shu[j+1]=temp;         }        }        if(b)break;              }       for(int i=0;i<10;i++){        System.out.print(shu[i]+",");       } } //判断是否与数组中其他值相同 public static boolean check(int c[],int t,int j){  for(int  i=0;i<c.length;i++){   if(c[i]==t&&j!=i){    return false;   }  }  return true; }}


0 0
原创粉丝点击