📄 vectortest.java
字号:
import java.util.*;
class VectorTest extends Object
{
public static Vector getRandomScores()
{
// 创建一个随机数产生器
Random rand = new Random();
// 随机数的范围设为 500到1000
int numElements = 500 + Math.abs(rand.nextInt())%501;
// 创建一个新的Vector并用一些随机数填充它
Vector v = new Vector(numElements);
while(numElements > 0)
{
// 添加一个在0到100之间的Integer
v.add(new Integer(Math.abs(rand.nextInt())%2001));
numElements--;
}
return v;
}
// 在一个填满随机数的Vector中找到最大的数
public static void main(String[] args)
{
int highestScore = 0; // 目前所找到的最大值
// 产生一些随机数
Vector scores = getRandomScores();
// 遍历这些数值并找出最大值
for(Enumeration e = scores.elements(); e.hasMoreElements(); )
{
Integer score = (Integer)(e.nextElement());
if(score.intValue() > highestScore)
{
highestScore = score.intValue();
}
}
// 打印最大值
System.out.println(highestScore);
}
} // VectorTest
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -