java高手请指教

来源:百度知道 编辑:UC知道 时间:2024/05/05 12:51:51
import java.util.*;
public class TestVector {

/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
int b = 0;
System.out.print("Enter you number:");
// TODO: Add your code here
Vector v = new Vector();
try{
b = System.in.read();}
catch(Exception e)
{System.out.print("unsupport");}
while(true)
{int num = b - 48;
v.addElement(new Integer(num));
int sum = 0;
Enumeration e = v.elements();

if(e.hasMoreElements())
{
Integer obcd =(Integer)e.nextElement();
sum+= obcd.intValue();
System.out.print(sum);}

}

}
}
程序要求输入123打印6 输入45打印9即输出几个数字的和
为什么这个程序只能输出第一个数字