Collection 与iterator接口
类别: JAVA教程
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);     }
}
/**
* 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);     }
}
-= 资 源 教 程 =-
文 章 搜 索