Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class VektorDemo
  4. {
  5. public static void main(String args[])
  6. {
  7. // Create a Integer Vector with Capacity 5 and Increment capacity 2
  8. // Size is Initially 0, since no Elements are added Yet
  9. // Wut Vector ? Dynamic Array
  10. Vector<Integer> someVector = new Vector<Integer>(5,2);
  11. System.out.println("Vector Initialized with Size " + someVector.size() + " and Capacity " + someVector.capacity());
  12. int op = 0;
  13. while(op!=5)
  14. {
  15. System.out.println("\n========= Vektor Menu =========");
  16. System.out.println("1. Add Element");
  17. System.out.println("2. Remove Element");
  18. System.out.println("3. Show Vektor Contents");
  19. System.out.println("4. Show Element at an Index\n");
  20. Scanner sc = new Scanner(System.in);
  21. op = sc.nextInt();
  22. switch(op)
  23. {
  24. case 1:
  25. System.out.println("\nSpecify the Element to add\n");
  26. someVector.addElement(sc.nextInt());
  27. break;
  28. case 2:
  29. System.out.println("\nSpecify the Index\n");
  30. int i = sc.nextInt();
  31. if(i>0 && i<someVector.size())
  32. someVector.removeElementAt(i);
  33. break;
  34. case 3:
  35. System.out.println("\nVektor Contents\n");
  36. for(int j = 0; j < someVector.size(); j++)
  37. System.out.println(someVector.get(j));
  38. break;
  39. case 4:
  40. System.out.println("\nSpecify the Index\n");
  41. int s = sc.nextInt();
  42. System.out.println("Element at Index " + s + " is " + someVector.get(s));
  43. default: System.out.println("\nInvalid Selection");
  44. }
  45. System.out.println("\nSize : " + someVector.size() + " Capacity : " + someVector.capacity() + "\n");
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement