📄 vectortest.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 + -