首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

请教vector出现的有关问题

2012-03-09 
请问vector出现的问题import java.util.*public class TestVector {/** * @param args */public static v

请问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);


}

}

[解决办法]
记在心里

热点排行