math类中有个random()方法,可以得到0到1中的随机数,你再乘个系数33,再加个类型转换,重复六遍,排序,ok

解决方案 »

  1.   

    class test
    {
    public static void main(String[] args)
    {
    int[] numbers = new int[6]; 
    for(int i=0;i<6;i++)
    {

    int temp = (int)(Math.random() * 33); // 0--32 
    numbers[i] = temp;
    }

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

    if(numbers[i]>numbers[j])
    {
    tp = numbers[j];
    numbers[j]=numbers[i];
    numbers[i]=tp;
    }
    }
    }

    for(int i=0;i<5;i++)
    {
    System.out.print(numbers[i]+" ");
    }

    }呵呵, 简单写了个
      

  2.   

    public class Sort {

    public static void main(String[] args){
    int[] array = new int[6];
    for(int i = 0; i < 6;i++){
    array[i]=(int)(33* Math.random());
    System.out.print(array[i]+" ");
    }
    sortArray(array);
    System.out.println("\nafter sort:");
    for(int i=0;i<6;i++){
    System.out.print(array[i]+" ");
    }
    }
    static void sortArray(int[] array){
    for(int i=0;i<6;i++)
    for(int j=i+1;j<6;j++){
    if(array[j]<array[i]){
    int temp=0;
    temp = array[i];
    array[i]=array[j];
    array[j]=temp;
    }
    }
    }
    }
      

  3.   

    random() + 排序算法的事.
      

  4.   

    public class TestRandom {
    public static void main (String[] args){
    TestRandom tr = new TestRandom();
    int haha[] = new int[6];
    for(int i = 0;i <= 5 ;i ++){
    haha[i] = (int)(33*Math.random());
    System.out.println(haha[i]);
    }
    int temp = 0 ;
    for(int k = 0;k <=5; k ++){
    for(int j = 0;j <= 4;j ++ ){
    if(haha[j] > haha[j+1]){
    temp = haha[j];
    haha[j] = haha[j+1];
    haha[j+1] = temp;
    }
    }
    }
    for(int i = 0;i <= 5 ;i ++){
    System.out.println(haha[i]);
    }

    }
    }
      

  5.   

    1。随机产生1-33同上用Math.random()方法
    2。排序时还可用到基本数据结构类Arrays中的sort()方法,充分利用组件技术
      

  6.   

    public class TestRandom {
    public static void main (String[] args){
    TestRandom tr = new TestRandom();
    int haha[] = new int[6];
    for(int i = 0;i < 6 ;i ++){
    haha[i] = (int)(33*Math.random());
    while( true ){
    int temp = 0;
    for(int j = 0; j < i;j ++  ){
    if(haha[i] == haha[j]||haha[i] == 0)haha[i] = (int)(33*Math.random());//判断是否和前数相等及是否为零.若是则重取随机数.
    else  temp ++;

    }
    if( temp == i)break;
    }
    System.out.println(haha[i]);
    }
    int temp = 0 ;
    System.out.println();
    for(int k = 0;k <=4; k ++){
    for(int j = 0;j <= 4-k;j ++ ){
    if(haha[j] > haha[j+1]){
    temp = haha[j];
    haha[j] = haha[j+1];
    haha[j+1] = temp;
    }
    }
    }
    for(int i = 0;i <= 5 ;i ++){
    System.out.println(haha[i]);
    }

    }
    }完善了下,没有逻辑上的问题了应该
      

  7.   

    注意一点,random()后值要全体加一,开始就不用判断是否为0了,要不最大值为32,到不了33,因为(int)强制转换是取整运算,不是四舍五入
      

  8.   

    怎么33*(1.0-random())怎么也得不到33啊?郁闷中,请朋友指点下~谢