?? 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 + -