当前位置: 代码迷 >> Java相关 >> 随机函数
  详细解决方案

随机函数

热度:453   发布时间:2010-05-26 20:48:43.0
随机函数
程序代码:
import java.awt.*;
public  class saolei
{
    public int w,h,i,j;
    //初始化数组

    public saolei()
    {
        int a[][]=new int[10][10];
       for( i=0;i<10;i++)
             {
               for( j=0;j<10;j++)
                a[i][j]=0;
               
              }
            
            
    //产生随机数   
      
         for( i=0;i<10;i++)
             {
              
      
              w=(int)(Math.random()*10);
              h=(int)(Math.random()*10);
      
             System.out.print(h+" ");
             System.out.printf(w+"  ");
           
            
            
             a[w][h]=-1;
              System.out.printf(a[w][h]+"  ");
                  
              System.out.println();
              
      
              }
            
              //输出
           
              for(i=0;i<10;i++)
              {
                  for(j=0;j<10;j++)
                 
                  if(i==h&&j==w)
                 
                  System.out.printf(a[w][h] +"  ");
                  else
                  System.out.printf(a[i][j] +"  ");
                  System.out.println();
                 
              }
   
    }
    public static void main(String arg[])
    {

      saolei s=new saolei();
   
    }
}
我是在10*10的数组随机的给数组赋一个定值,怎么能保证他不重复呢
搜索更多相关的解决方案: 随机函数  

----------------解决方案--------------------------------------------------------
请参考我在第11楼的回帖。
http://bbs.bccn.net/thread-305828-1-1
----------------解决方案--------------------------------------------------------
第12楼的,我看错了,不好意思
----------------解决方案--------------------------------------------------------
  相关解决方案