public static void main (String args[]) 
     {
     int a[] = setupArray(100);
     System.out.println(showArray(a));
     /*下面代码小弟看不懂,很惭愧,请高手指导一下*/
     // 計數器的數組,分別計數0-9
     int count[]={ 0,0,0,0,0,0,0,0,0,0};
     for(int i=0 ;i<a.length; i++)
        // a[i]為0-9的數,因此,count[a[i]]++指a[i]對應的計數器增加一
        count[a[i]]++;
     
     
     System.out.println("随机数\t次数\n------\t----");
     // 打印結果麼
     for(int=0 ; i<count.length; i++ )
     System.out.println(i+ "\t" +count[i]);
     }

解决方案 »

  1.   

    /*这段代码,小弟我看不懂啊,哎,还要麻烦大哥说明详细呀 555!~~~*/
                for( int i=0; i<suit.length: i++)
                   {
                   while (true)
                     {
                     key=(int)(Integer.MAX_VALUE*Math.random())%sw.length;
                     if(sw[key]==false) break;
                     }
                 suit[i]=key;
                 sw[key]=true;
                     }
                 for (int i=0; i<suit.length; i++);
                 System.out.print();
          }
    //我想應該為
    public class CardSuit {
        public static void main(String args[]) {
            int key, suit[] = new int[13];
            boolean sw[] = new boolean[22];
            for (int i = 0; i < suit.length ; i++) {
                while (true) {
                    key = (int) (Integer.MAX_VALUE * Math.random()) % sw.length;
                    if (sw[key] == false)
                        break;
                }
                suit[i] = key;
                sw[key] = true;
            }
            for (int i = 0; i < suit.length; i++)
            System.out.println("" + suit[i]);
        }
    }
      

  2.   


                while (true) {
                    key = (int) (Integer.MAX_VALUE * Math.random()) % sw.length;
                    if (sw[key] == false)
                        break;
                }
                
    这里的第一个true从那里来的?
    第一个true代表什么呢?
    以后循环中的true是从那里来的呢?
      

  3.   

    while(true)也就是无限循环了,当检测到sw[key]==false的时候,就跳出循环
    当然,你写while(1)也是一样的
      

  4.   

    楼上的已经说了!就是造了一个无限循环!
    不过他说的while(1)应该是不行的!在JAVA中不支持这样!boolean 与int 不兼容!
    可以这样写!
    while(2==2){
    }
    呵呵!
      

  5.   

    public class RandInt
         {
         static int[] setupArray(int n)
           {
            int a[] = new int[n];
            for ( int i=0 ; i<a.length; i++)
               
                a[i]=(int)(Math.random()*10);
                return a;
               }
              
          static String showArray(int a[])
             {
             String s = "建立" +a.length + "个随机数如下:";
             for(int i =0 ; i<a.length; i++)
                {
                 if(i%10 == 0)
                  s=s + "\n" ;
                 else
                  s=s + a[i] + " " ;
                 }
                  s=s + "\n";
                  return s;
                 }
      public static void main (String args[]) 
        {
        int a[] = setupArray(100);
        System.out.println(showArray(a));
        
        int count[]={ 0,0,0,0,0,0,0,0,0,0};
        for(int i=0 ;i<a.length; i++)
           count[a[i]]++;
        System.out.println("随机数\t次数\n------\t----");
        
        }
    }为何报错,请教高手..!!!