source file name: enumdemo.java
import java.util.*;
class enumdemo
{
public static void main(String as[])
{
System.out.println("Vector demo program");
Vector v=new Vector();
Object ob;
for(int i=0;i<as.length;i++)
{
ob=new String(as[i]);
v.add(ob);
}
System.out.println("vector v="+v);
String s1="123";
String s2="456";
v.add(s1);
v.add(s2);
System.out.println("after adding 2 strings vector v="+v);
Enumeration e=v.elements();
double sum=0.0;
while(e.hasMoreElements())
{
ob=e.nextElement();
double n=Double.parseDouble(ob.toString());
sum=sum+n;
System.out.println(ob);
}
System.out.println("sum="+sum);
}
}
output:
D:\JavaPrograms>java enumdemo 15 25 2.5 3.6
Vector demo program
vector v=[15, 25, 2.5, 3.6]
after adding 2 strings vector v=[15, 25, 2.5, 3.6, 123, 456]
15
25
2.5
3.6
123
456
sum=625.1
0 Comments
Post a Comment