Thursday, 11 August 2016

Vector program in java

import java.io.*;
import java.util.*;
class VectorDemo1
{
public static void main(String args[]) throws IOException
{
Vector v = new Vector( );
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.println("1.Creation");
System.out.println("2.Insertion");
System.out.println("3.Deletion");
System.out.println("4.Display");
System.out.println("5.exit");
System.out.println("Enter Ur Choice:");
int n=Integer.parseInt(br.readLine());
switch(n)
{
    case 1:    
        System.out.println("Enter the Element:");
        v.addElement(new Integer(br.readLine()));
        break;
    case 2: System.out.println("Enter the position to be inserted:");
        int x=Integer.parseInt(br.readLine());
        System.out.println("Enter the Element:");
        int y=Integer.parseInt(br.readLine());
        v.insertElementAt(y,x);
        break;
    case 3:System.out.println("Enter the position to be deleted:");
        int z=Integer.parseInt(br.readLine());
        v.removeElementAt(z-1);
        break;
    case 4: System.out.println("Elements are:");
        for(int i=0;i<v.size();i++)
        System.out.println(v.get(i)+" ");       
        break;
    case 5:System.exit(0);
}
}
}
}

Post a Comment