大家帮我看下这代码最后运行时怎么不进行加法运算
package testVector;
import
java.io.IOException;
import java.util.*;
public class TestVector {
public static void main(String[] args)
{
int b=0;
Vector v=new Vector();
System.out.println("please enter number:");
while(true)
{
try {
b=System.in.read();
} catch (
IOException e) {
e.printStackTrace();
}
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);
}
}
------解决方案--------------------能加,输入时要这样:
1234ar