/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
int ch = 0;
int pos = 0;
String str = null;
byte[] buf = new byte[1024];
System.out.println("Please input info");
while(true){
ch = System.in.read();
switch (ch) {
case '\r':
break;
case '\n':
str = new String(buf,0,pos);
// String a[] = str.split("");
Pattern p = Pattern.compile("[0-9]");
Matcher m = p.matcher(str);
int result = 0;
while(m.find()) {
int temp = Integer.parseInt(m.group());
result = result + temp;
}
// String a[] = str.
/*int result = 0;
for (int i = 0; i < a.length; i++) {
int temp = Integer.parseInt(a);
result = result + temp;
}*/
System.out.println(result);
pos = 0;
break;
default:buf[pos++] = (byte)ch;
break;
}
}
ch = System.in.read();//read返回的是int,下面怎么能用字符来做判断标记
switch (ch) {
case '\r':
break;
case '\n':
str = new String(buf,0,pos);//System.In没有在buf存入过东西所以你这语句就变成了
str = new String(null,0,pos);不可能有你要的结果。