import java.util.*;
public class TestVector {

/**
 * Method main
 *
 *
 * @param args
 *
 */
public static void main(String[] args) {
// TODO: Add your code here
Vector v = new Vector();
int b = 0;
// Enumeration e = new Enumeration();
System.out.println("please enter number:");
while(true)
{
try
{
 b = System.in.read();
}
  catch(Exception e)
  {
 
  }
  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);
}
}
程序通过编译,但是提示使用了未经检查或不安全的操作。
要了解详细信息,请使用 -Xlint:unchecked 重新编译。
是什么原因导致的提示?
另外怎么编写能使此程序重复运行。直到用户输入bye的时候退出程序?

解决方案 »

  1.   

    jdk1.5的泛型
    声明collection的时候指明存储的类型就没有警告了
    楼主可以改成 Vector<Integer> v = new Vector<Integer>();
      

  2.   

    泛型(Generics)--为集合(collections)提供编译时类型安全,无需每刻从Collections取得一个对象就进行强制转换(cast) 通过引入泛型,我们将获得编译时类型的安全和运行时更小地抛出ClassCastExceptions的可能。
      

  3.   

    Vector是废弃的类,楼主还用它干吗?
      

  4.   

    你按照 JDK 编译时给出的提示 使用 -Xlint:unchecked 重新编译一次看看先。
    java.sun.com 上面有很多文档和 Tuturial .
      

  5.   

    Vector是废弃的类,已经暗示以后的版本不一定支持~~~~