/*
将键盘上输入的一个数字序列中的每一位数存储在Vector对象中,
然后在屏幕上打印出每位数字相加的结果
*/
import java.util.*;
public class VectorTest
{
public static void main(String[] args)
{
Vector v = new Vector();
System.out.println("Please enter number:");
while(true)
{
int b = 0;
try
{
b = System.in.read();
}
catch(Exception e)
{
e.printStackTrace();
}1
if(b=='\r' || b == '\n')
break;
else
{
int num = b - '0';
v.addElement(new Integer(num));
}
}
int sum = 0;
Enumeration e = v.elements();
while(e.hasMoreElements())
{
Integer intObj = (Integer)e.nextElement();
sum += intObj.intValue();
}
System.out.println(sum);
}
}编译结果显示:
注: VectorTest.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。百度了一下,很多类似的错误是没有用泛型的问题,可怎么修改呢?泛型