为何输入0时,输出-35?
import java.util.*;
public class Projection1 {
public static void main(String[] args) {
Vector v = new Vector();
int sum = 0;
int num = 0;
while(true)
{
try
{
num = System.in.read();
}
catch(Exception ex){ex.printStackTrace();}
if(num == '\n')
break;
else
num = num-'0';
v.addElement(new Integer(num));
}
Enumeration e = v.elements();
while(e.hasMoreElements())
{
Integer intObj = (Integer)e.nextElement();
sum+=intObj.intValue();
}
System.out.println(sum);
}
} |
|