三个数{10,20,50}
要求
1.用户选择要第1个或第2个或第3个数,该数从以上三个数中随机抽出
2.另2个数从余下的数中再次随机抽出,将新顺序的三个数打印出来
3.将用户选择的数与另2个数的和做比较,看谁的大?举例说:
用户抽第3个数,从{10,20,50}中随机抽出的是20,
然后从剩下的10,50中再随机抽出一个假设是50,作为第一个数
然后将剩下的10作为第二个数
按照一下格式打印这三个数
第三个数(你选的数) 20 
第一个数       50
第二个数       10然后比大小

解决方案 »

  1.   

    用容器添值去值  math的random()选择 ,不知道可以否?我也是菜鸟,等待神牛们出现
      

  2.   

    so fuliar just it is!
      

  3.   

    像你说的只有三个数的话 就好办了!import java.util.*;public class  helloworld
    {
    public static void main(String[] args){
    int[] x = {10,20,50};
    Random r = new Random();
    int num1;
    int num2;
    int num3;
    int rd = r.nextInt(3);//产生0到3的随机数不包含3
    num1 = x[rd];//取出数组中随机产生的数

    int[] x2 = new int[2];
    if(rd == 0){
    x2[0] =20;
    x2[1] = 50;
    }
    else if(rd==1){
    x2[0] = 10;
    x2[1] = 50;
     }
    else if(rd == 2){
    x2[0] = 10;
    x2[1] = 20;
    }//将另外两个数放入x2数组中.
    int rd2 = r.nextInt(2);//产生0到2的随机数 不包含2
    num2 = x2[rd2];
    if(rd2 == 0){
    num3 = x2[1];
    }else {num3 = x2[0];}
    System.out.println(num1+","+num2+","+num3);
    System.out.println(num1>(num2+num3)?"第一个随机数大于其它两数的和":"第一个随机数小于其它两数的和");

    }
    }
      

  4.   


    public class  helloworld
    {
    private static Random r = new Random();//这里也可以把Random 放在main方法外面 比较好一点
    public static void main(String[] args){

    }
    }
      

  5.   

    模拟从n个数的集合中随机抽取m个数的小程序=。=    public static void main(String[] args) {
    int n =20;
    int m =10;
    ArrayList list = new ArrayList();
    for(int i=0;i<n;i++){
    list.add(Integer.valueOf(i+1));
    }
    ArrayList result = new  ArrayList();
    //模拟抽取m个数的过程
    while(result.size()<m){
    int random = (int) (Math.random()*list.size());
    result.add(list.remove(random));
    }
    System.out.println(result);
    }
      

  6.   

    import java.util.Random;
    public class Rdarray {
    public  static int array[] = {5,50,100};

    public void setNew(){
        Random random = new Random();
        for(   int   i=0;   i <array.length;   i++){ 
    int index   =   random.nextInt(i+1); 
    int   temp   =   array[i]; 
    array[i]   =   array[index]; 
    array[index]=   temp; 

        
        //return array[1];
    }
    public int ji(){
    int ji = array[2];

    return ji;

    }
    }
    写了段取随机数的方法但传输去的数据还是原来的何解?