⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vectortest.java

📁 本源码演示Vector的使用方法
💻 JAVA
字号:
     import java.util.*;

     class VectorTest extends Object
     {
          public static Vector getRandomScores()
          {
               // create a random number generator
               Random rand = new Random();

               // generate between 500 and 1000 random scores
               int numElements = 500 + Math.abs(rand.nextInt())%501;

               // create a new Vector and fill it in with a bunch of random scores
               Vector v = new Vector(numElements);
               while(numElements > 0)
               {
                    // add an Integer between 0 and 2000
                    v.add(new Integer(Math.abs(rand.nextInt())%2001));
                    numElements--;
               }

               return v;
          }

          // finds the greatest score within a vector of random scores
          public static void main(String[] args)
          {
               int highestScore = 0;    // the highest score we've seen sofar

               // generate some random scores
               Vector scores = getRandomScores();               
               
               // cycle through the enumeration of the scores and pick out
               // the highest one
               for(Enumeration e = scores.elements(); e.hasMoreElements(); )
               {
                    Integer score = (Integer)(e.nextElement());

                    if(score.intValue() > highestScore)
                    {
                         highestScore = score.intValue();
                    }
               }   

               // print out the highest score
               System.out.println(highestScore);
          }
     }    // VectorTest

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -