.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> OOPS >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Java programing using vector class

Posted By:laptop charles       Posted Date: June 29, 2010    Points: 10    Category: OOPS    URL: http://www.dotnetspark.com  

Vector class using java to manipulate the values.
 

Vector class using java to manipulate the values.
1)add,
2)delete,
3)display.
4)insert the value to vector class.
import java.io.*;
import java.util.*;
class cha
  {
   public static void main(String a[])throws IOException
    {
     String s;
     int i,n=0,c;
      BufferedReader b=new BufferedReader(new InputStreamReader(System.in));

     Vector v=new Vector();

     do
      {
       System.out.println("Main Menu");
       System.out.println("---------------");
       System.out.println("1.Add");
       System.out.println("2.Display");
       System.out.println("3.Insert");
       System.out.println("4.Delete");
       System.out.println("5.Exit");

       System.out.println("Enter your choice");
       c=Integer.parseInt(b.readLine());       
                 
       switch(c)
        {
        case 1:
                  System.out.println("Enter how many data");
                  n=Integer.parseInt(b.readLine());
                  for(i=1;i<=n;i++)
                     {
                      System.out.print("Enter "+i+" element= ");
                      s=b.readLine();
                      v.addElement(s);
                     }
                  break;
       case 2:
                  for(i=1;i<=v.size();i++)
                     {
                      System.out.println(i+"Element="+v.elementAt(i));
                     }   
                  break;
       case 3:
                   System.out.println("Insert element");
                   System.out.println("Enter location");  
                   int l=Integer.parseInt(b.readLine());
                   System.out.println("Enter element");
                   s=b.readLine();   
                   v.insertElementAt(s,l);
                   break;

                      
       case 4:
                  System.out.println("Do you want Delete all element");
                  System.out.println("Yes/No=Y/N");
                  String cc=b.readLine();
                  while(cc=="y"||cc=="Y")
                      {
                       for(i=1;i<=n;i++)
                        v.removeElementAt(i);
                      }
                  System.out.println("Enter Element to be Deleted");
                  int d=Integer.parseInt(b.readLine());
                  v.removeElementAt(d);
                   break;
       default:
                  System.out.println("Invalid entry");
                  break;   
     
    }
  }
while(c!=5);
}
} 

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend