Ex:  A vector V is known to contain only Float's.  Find the sum.

 

Vector V;
  :
  :
  put Floats into V

 

float sum = 0;
Enumeration e = V.elements();
while( e.hasMoreElements() )
  {
  sum += ((Float)e.nextElement()).floatValue();
  }          
//sum contains total

 

for( Enumeration e = V.elements(); 
     e.hasMoreElements();        )
  {
  sum += ((Float)e.nextElement()).floatValue();
  }

 

To Next Slide To Previous Slide To Contents