请问vector出现的问题
import java.util.*;
public class TestVector {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Vector v = new Vector();
System.out.println("please enter number:");
int ch = 0;
int num = 0;
try
{
ch = System.in.read();
}catch(Exception e)
{
e.printStackTrace();
}
while(true)
{
if(ch=='\r' || ch=='\n')
break;
else
{
num = ch-'0';
int num = new Integer(num);//出现:Duplicate local variable num;
v.addElement(num);//为什么出现:Type safety:The method addElement(Object) belongs to the raw type Vector.References to generic type Vector<E> should be parameterized.
}
}
int sum = 0;
Enumeration e = v.elements();
while(e.hasMoreElements())
{
Integer intObj = (Integer)e.nextElement();
sum += intObj.intValue();
}
System.out.println(sum);
}
}
------解决方案--------------------
记在心里