import java.util.*;
/**
* Collection 与iterator接口
*
*
**/
public class TestCollection
{
 public static void main(String args[])
{
ArrayList v = new ArrayList();
 int b = 0;
 System.out.println("please input the number:");
 while(true)
{
 try
{
 b = System.in.read();
}
 catch(Exception e)
{
 e.printStackTrace();
}
 if(b=='\r' || b=='\n')
{
 break;
}
 else
{
 int num = b -'0';
 v.add(new Integer(num));
}
}
 int sum = 0;
 Iterator e = v.iterator();
 while(e.hasNext())
{
 Integer intObj = (Integer)e.next();
 sum += intObj.intValue();
}
 System.out.println(sum); }
}
时间: 2024-10-24 19:22:17