当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

 ·三国人物中,大家最欣赏谁    »显示摘要«
    摘要: 我最欣赏董卓,敢爱敢恨 武勇有余,又不乏智谋 ......
 ·java高手请进    »显示摘要«
    摘要: 。 ......


一个基础问题,大家帮帮忙啊

JAVA中,有没有这么一个容器,就是可以把产生的值按编号放入这个容器中。。。  
  比如我产生了50个值  
  for   (int   i=0;i<50;i++)  
  {  
      System.out.println(Math.random());  
  }  
  想把这个值按i的编号放入一个容器中,调用的时候可以通过编号调用,如果编号相同的,则覆盖,不同的,则加入,容器自动按编号大小排列。  
  比如  
  public   class   asdf2   extends   Thread  
  {  
      double   sum;  
      public   void   run()  
      {  
          for   (int   j=0;j<10;j++)  
          {  
                  for   (int   i=0;i<50;i++)  
                  {  
                      sum+=Math.random();  
                  }  
            //把sum结果按j加入一个容器  
            }  
      }  
        public   static   void   main(String[]   args)  
        {  
              for   (int   i=0;i<10;i++)  
              {  
                  new   asdf2().start();  
                  //把sum按j的结果打印出来  
              }  
        }  
  }

NO.1   作者: dojsp

帮你UP

NO.2   作者: do_do

You   could   use   Vector   (as   in   following   example).   Be   aware   that   the   values   (the   sums)   are   not   sorted   but   their   corresponding   index   are.  
   
  package   test;  
   
  import   java.util.Vector;  
   
  public   class   asdf2  
          extends   Thread   {  
      static   Vector   container_   =   new   Vector();  
      public   void   run()   {  
          for   (int   j   =   0;   j   <   10;   j++)   {  
              double   sum   =   0;  
              for   (int   i   =   0;   i   <   50;   i++)   {  
                  sum   +=   Math.random();  
              }  
              synchronized   (container_){  
                  container_.add(j,   new   Double(sum));  
              }  
          }  
      }  
   
      public   static   void   main(String[]   args)   {  
          int   numberOfThreads   =   10;  
          asdf2[]   threads   =   new   asdf2[numberOfThreads];  
          for   (int   i   =   0;   i   <   numberOfThreads;   i++)   {  
              threads[i]   =   new   asdf2();  
              threads[i].start();  
          }  
          for   (int   i   =   0;   i   <   numberOfThreads;   i++)   {  
              try   {  
                  threads[i].join();  
              }   catch   (java.lang.InterruptedException   ex){  
                  ex.printStackTrace();  
              }  
          }  
          for   (int   i   =   0;   i   <   numberOfThreads;   i++)   {  
              System.out.println(container_.get(i));  
          }  
      }  
  }


    摘要: 对vc的界面编写很不熟悉,vb中,每个控件都有个tabindex,可以给每个控件的tabindex赋不同值,按tab键时,焦点就会按照tabindex从小到大的顺序在各个控件上移动,vc中如何实现这样的功能呢?谢谢! ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE